js map()
var number = [1, 2 , 3, 4, 5, 6, 7, 8, 9]; var doubles = number.map((n) => { return n*2 }) /* doubles (9) [2, 4, 6, 8, 10, 12, 14, 16, 18] */
how to use the map method in javascript
const numbers = [1, 2, 3, 4, 5]; const bigNumbers = numbers.map(number => { return number * 10; });
Source: www.codecademy.com
array mdn map
let new_array = arr.map(function callback( currentValue[, index[, array]]) { // return element for new_array }[, thisArg])
Source: developer.mozilla.org
array.map
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]
map javascript
test.map(x=> x)
js array map
let A = [9000, 8500, 5500, 6500]; let B = A.map(function (value, index, array) { return value*2; // forEach 沒有在 return 的,所以不會有作用 }); console.log(B); // undefined
Source: ithelp.ithome.com.tw