Last active
January 22, 2020 18:40
-
-
Save shivenigma/01f08afce152370cb587c2f13bc6660e to your computer and use it in GitHub Desktop.
Javascript array methods
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
arr.forEach(callback, [, thisArg]); | |
// thisArg is optional for forEeach | |
// the callback has the following arguments in forEach. | |
callback(currentValue, [, index [, array]]) | |
// index and array are optional |
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
const names =["Javascript", "Python", "PHP", "Flutter"]; | |
names.forEach(name => { | |
console.log(name); | |
}); | |
// OUTPUT | |
// > Javascript | |
// > Python | |
// > PHP | |
// > Flutter |
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
let newArray = arr.map(callback, [, thisArg]); // thisArg is optional | |
callback(currentValue, [, index, [, array]]); // index and array are optional | |
// the callback must return an element for the new array after applying any transformation |
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
const names =["Javascript", "Python", "PHP", "Flutter"]; | |
const newNames = names.map((name, index) => { | |
return index.toString() + '. ' +name; | |
}); | |
console.log(newNames); | |
// OUTPUT : Array ["0. Javascript", "1. Python", "2. PHP", "3. Flutter"] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment