Array.prototype.myForEach = function(element) {
for (var i = 0; i < this.length; i++) {
element(this[i], i, this);
}
};
var forArr = ['8', '17', '25', '42','67'];
forArr.myForEach(function(exm){
console.log(exm);
});
I wrote in the form. Can you help in translating this into recursive?
var forArr = ['8', '17', '25', '42','67'];
var recursive_function = function(array){
if(array.length > 0){
console.log(array[0]);
recursive_function(array.slice(1))
}
}
recursive_function(forArr)
Array.shift will do the trick here
var forArr = ['8', '17', '25', '42', '67'];
function recursivearray(array) {
if (array.length > 0) {
console.log(array.shift());
recursivearray(array);
}
}
recursivearray(forArr);
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