Flat array flat

This method does not change the original array argument: integer, representing flat dimensions, default value is 1, if you want to flat no matter how many dimensions, pass Infinity(Infinity) return value: flat one-dimensional array

            let arr = [[1.2.3], [4.5[6]]]
		    console.log(arr);
        	console.log([[1.2.3], [4.5.6]].flat(Infinity));
Copy the code
To judge some

Function: Returns true as long as one of the conditions is met

let arr = [
		{
			id:1.age:18.name:'Joe'
		},
		{
			id:1.age:19.name:'Joe'
		},
		{
			id:1.age:17.name:'Joe'}]let arr2 = arr.some(function(item){
		return item.age > 18
	}) // true
Copy the code
Every judgment

What it does: Returns false as long as one does not meet the criteria

// refer to some methods
 let newArr = arr.every(function(item){
		return item.age > 18
	}) // false
Copy the code
The filter to filter

Effect: Filter (filter) to meet the specified conditions, generate a new array return

// refer to some methods
let arr3 = arr.filter(function(item){
    return item.age > 18
})
console.log(arr3) // [{age: 19 id: 1 name: "zhang3 "}]
Copy the code
ForEach traverses the array
// some methods are used for reference
    arr.forEach(function(item,index,arr){
		console.log(item,index,arr)
		// item represents each item of the array, index represents the current subscript, and arr represents the array itself
	})Copy the code