Skip to content

Instantly share code, notes, and snippets.

@suhailgupta03
Created August 17, 2023 14:48
Show Gist options
  • Save suhailgupta03/4410e959403a91582901c346ad727c0e to your computer and use it in GitHub Desktop.
Save suhailgupta03/4410e959403a91582901c346ad727c0e to your computer and use it in GitHub Desktop.
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)
@suhailgupta03
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment