I want to do something like this:
const foo = ['aba', 'bab'];
const bar = [1, 2];
and then create this array:
result = [
{
text: foo[0]
number: bar[0]
},
{
text: foo[1]
number: bar[1]
}
]
Foo and bar will have equal lengths.
If your arrays have same length, you can use Array#map to iterate over each item, get the item and the index and then create the new array of objects setting the text to item and the number to bar[index].
const foo = ['aba', 'bab'];
const bar = [1, 2];
const mapped = foo.map((item, index) => ({text: item, number: bar[index]}));
console.log(mapped);
fooandbaralways be the same length?