Created
August 17, 2023 14:48
-
-
Save suhailgupta03/4410e959403a91582901c346ad727c0e to your computer and use it in GitHub Desktop.
This file contains hidden or 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 list = [1,2,3,4,5]; | |
let newList = []; // [2,3,4,5,6] | |
// we can use a map function to achieve this | |
// map function takes a callback function as an argument | |
// and returns a new array | |
let result = list.map(function(item) { | |
return item + 1 | |
}) | |
console.log(result) | |
// for(let i = 0; i<list.length; i++) { | |
// const newNunber = list[i] + 1; | |
// newList.push(newNunber); | |
// } | |
// console.log(newList) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
MDN Documentation: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map