I have rewritten a version of each below. In my output I want it to log
[['motorbike', 0, vehicles],[['car', 1, vehicles]],[['plane', 2, vehicles]]]
However it currently logs the entire contents of the array rather than just the title. How can I get it to provide the the list name instead?
function each(collection, callback) {
if (Array.isArray(collection)) {
for (var i = 0; i < collection.length; i++) {
callback(collection[i], i, collection);
}
} else {
return collection;
}
}
var vehicles = ['motorbike', 'car', 'plane'];
var iterationInputs = [];
each(vehicles, function(vehicle, index, list) {
iterationInputs.push([vehicle, index, list]);
});
console.log(iterationInputs);