filter
The filter() method creates a new array of elements by checking all eligible elements in the specified array. Note: Filter () does not detect an empty array. Filter () does not change the original array. Array. filter(function(currentValue,index,arr), thisValue)
map
The map() method returns a new array whose elements are the values processed by the call to the original array element. Note: Map () does not detect empty arrays. Map () does not change the original array. Array. map(function(currentValue,index,arr), thisValue)
- describe
CurrentValue must. The current element value index is optional. The current element index value arr is optional. The array object to which the current element belongs
concat
The concat() method is used to merge two or more arrays. This method does not change an existing array, but returns a new array. Note: concat() does not alter the original array. If valueN is omitted, concat returns a shallow copy of the OLD_array array. Var new_array = old_array.concat(value1[, value2[,…[, valueN]]])
reverse
The reverse() method is used to reverse the order of elements in an array. It returns the array upside down, changing the original array.
Var arr = [1, 2, 3]; console.log(arr.reverse()); //[3, 2, 1] console.log(arr); / / [3, 2, 1)Copy the code
Note: Reverse () changes the original array.
Every with some
The every and some methods check whether each item in the array is full or not. Every means that each item satisfies and returns true, otherwise false. Some returns true if there are any in the array, false otherwise.
Var arr = [1,2,3] var res = arr.every(function(item,index){return item > 2}) console.log(res) // false var res = arr.some(function(item,index){ return item > 2 }) console.log(res) // trueCopy the code
set
The set() method is used to redo an array.
var mySet = new Set([1, 2, 2, 3]); let newArr = Array.from(mySet); console.log(newArr); / / [1, 2, 3]Copy the code
The expansion operator… (Dot dot dot)
[...mySet]; / / [1, 2, 3]
flat
The flat() method converts nested arrays to one-dimensional arrays. Flat (depth), depth, represents the depth to expand the nested array, the default is 1
let arr = [1, [2, 3, [4, [5]]]]; arr.flat(3); / / [1, 2, 3, 4, 5]Copy the code
Arrow function
Arrow functions are new to the ES6 standard, simplifying the definition of functions.
Arrow function: x => x * x
function (x) {
return x * x;
}
Copy the code
Note: Arrow functions have two formats. One, like the one above, contains only one expression, with {} and return omitted. The other option is to include multiple statements, so {} and return cannot be omitted:
arr.map((x, y) => {
return ???
});
Copy the code