let numbers =[1,2,3,4]let filteredNumbers = numbers.map(function(_, index){if(index <3){return num
}})// index goes from 0, so the filterNumbers are 1,2,3 and undefined.// filteredNumbers is [1, 2, 3, undefined]// numbers is still [1, 2, 3, 4]
let arr =[1,2,3]/*
map accepts a callback function, and each value of arr is passed to the
callback function. You define the callback function as you would a regular
function, you're just doing it inside the map function
map applies the code in the callback function to each value of arr,
and creates a new array based on your callback functions return values
*/let mappedArr = arr.map(function(value){return value +1})// mappedArr is:>[2,3,4]
functionsquare(arr){const newArr = arr.map(x=> x * x );return newArr ;//if you find this answer is useful ,//upvote ⇑⇑ , so can the others benefit also . @mohammad alshraideh ( ͡~ ͜ʖ ͡°)
myRange =[0,1,2,3,4,5,6,7,8,9,10,11]//understanding map power is similar to forEach, but concise//creating objectsconst newRange = myRange.map((d)=>({num: d *5,tuo: d *50}));//creating updated rangesconst newRange = myRange.map((d)=>d *5);
let numbers =[1,2,3,4]let filteredNumbers = numbers.map(function(num, index){if(index <3){return num
}})// index goes from 0, so the filterNumbers are 1,2,3 and undefined.// filteredNumbers is [1, 2, 3, undefined]// numbers is still [1, 2, 3, 4]