Typescript also works
Lets say I have an array like this
const array = ['one', 'two', 'three', 'four', 'five']
And I want to produce some components that would look like
<div>
one
two
</div>
<div>
three
four
</div>
<div>
five
</div>
If I wanted to use the map function, to the best of my knowledge I would have to write something like
{
let saved
array.map((item) => {
if (saved === ''){
let temp = saved
saved = ''
return (
<div>{`${item} ${temp}`}</div>
)
}else{
saved = item
}
})
}
But I would like to clean this code up a bit. I'm looking for a way that I can use the map function(or forEach) to iterate over the array moving across 2+ items at a time, so that the above code could be shortened to something like below, and produce the same result.
array.map((item1, item2) => <div>{`${item1} ${item2}`}</div>)