Created
April 6, 2018 06:26
-
-
Save rao123dk/11d0a871102f621a00259ed8b85fb3cd to your computer and use it in GitHub Desktop.
Own for each for array in JavaScript.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var array_list = [1,2,3,4,5,3]; | |
Array.prototype.raoEach = function(cb){ | |
for (i = 0; i < this.length; i++) { | |
cb(this[i]); | |
} | |
} | |
array_list.raoEach(function(a){ | |
console.log(a+2); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is updated code for also return index position.
var array_list = [1,2,3,4,5,3];
Array.prototype.raoEach = function(cb){
for (i = 0; i < this.length; i++) {
cb(this[i] , i);
}
}
array_list.raoEach(function(a,index){
console.log(a+2 , index);
});