I'm trying to combine two arrays and most of the answers relate to adding the second array to the end of the first. I need to merge index to index.
Here's example code:
let arr1 = ['golf', 'hockey', 'tennis'];
let arr2 = ['player1', 'player2', 'player3'];
Array.prototype.zip = function (arr) {
return this.map(function (e, i) {
return [ e, arr[i]];
})
};
const arr3 = arr1.zip(arr2);
console.log(arr3);
The result should be:
['golf', 'player1', 'hockey', 'player2', 'tennis', 'player3']
The above code looks like it should work but doesn't. If it can be fixed, or exchanged for better that would be great.....