Currently in React, I am using array.map(function(text,index){})
to iterate through an array. But, how am I going to iterate through two arrays simultaneously u
Generally, what you're looking for is a zip
function, such as the one that lodash provides. Much like a real zipper, it combines two things of the same length into one:
const zipped = _.zip(sentences, icons);
return (
{zipped.map(([sentence, icon], index) => (
{text} ;
))}
);
Note, this is doing more iterations than are technically needed. If performance is an issue, you may want a solution that's a bit smart (not really in scope for your question though).