const array1 = [1, 4, 9, 16]; // pass a function to map const map1 = array1.map(x => x * 2); console.log(map1); // expected output: Array [2, 8, 18, 32]
function listFruits() { let fruits = ["apple", "cherry", "pear"] fruits.map((fruit, index) => { console.log(index, fruit) }) } listFruits() // https://jsfiddle.net/tmoreland/16qfpkgb/3/
const sweetArray = [2, 3, 4, 5, 35] const sweeterArray = sweetArray.map(sweetItem => { return sweetItem * 2 }) console.log(sweeterArray)
array.map(function(currentValue, index, arr), thisValue)
let numbers = [1, 4, 9] let roots = numbers.map(function(num) { return Math.sqrt(num) }) // roots is now [1, 2, 3] // numbers is still [1, 4, 9]
var numbers = [4, 9, 16, 25]; var x = numbers.map(Math.sqrt) document.getElementById("demo").innerHTML = x;
let new_array = arr.map(function callback( currentValue[, index[, array]]) { // return element for new_array }[, thisArg])
let A = [{ x:'x', y:'y' }, { x:'x', y:'y' }]; let result = A.map(({y,...rest})=> ({...rest,v:y})); console.log(result);