I am trying to figure out how to loop through several array arguments passed. For example: [1,2,3,4,5],[3,4,5],[5,6,7] If I pass it to a function, how would I have a function loop inside each argument (any number of arrays can be passed) ?
I want to use a for loop here.
Use forEach, as below:
'use strict';
function doSomething(p1, p2) {
var args = Array.prototype.slice.call(arguments);
args.forEach(function(element) {
console.log(element);
}, this);
}
doSomething(1);
doSomething(1, 2);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With