JavaScript-关于js数组的笔记

记录在 开发中遇到的一些 js 数组的笔记

map 转换数组

The map() method creates a new array with the results of calling a provided function on every element in the calling array.

1
2
3
4
5
6
7
var 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]
0%
隐藏