6
var kiko = [1,2,3,4,5,6];
var forEach = function(array, newArray, action){
for (var i=0; i<array.length; i++){
var newArray = [];
newArray.action(array[i]);
};
};
forEach(kiko, newKiko, push)
newKiko
I’m studying abstract functions, and I came across an example from the book Eloquent Javascript in which a version of array.map is created from scratch. I tried to make mine, which scans an array, and creates another array for each item you go through. I am getting "Push is not defined" error but it is a native method of arrays in JS. What may be going wrong?
I tried a second variation, but it gives me an empty array:
var kiko = [1,2,3,4,5,6];
var forEach = function(array, action){
for (var i=0; i<array.length; i++){
action(array[i]);
};
};
forEach(kiko, function(element){
var newKiko = [];
newKiko.push(element);
})
newKiko
push
is a function ofArray
, is not a global function. http://www.w3schools.com/jsref/jsref_push.asp– Maicon Carraro
newKiko is an array! It does not work with it?
– Kvera