Whether there is an array of a specified value to re-summing the array value based on the condition determination Array array value is determined recursively alternative splicing arrays of arrays in the array

Here are some common property or method of learning about the array operation during recording, record it for later use.
// array deduplication 
var arr1 = [1,1,2,3,4,5,6,3,2,4,5, 'a ', 'b', 'c', 'a', 6,7 , 8,3,5,7,8,34] 
// the console.log (Array.from (the Set new new (of arr1))) // [. 1, 2,. 3,. 4,. 5,. 6, "A", " B "," C ",. 7,. 8, 34 is] 


// array of splicing concat () this method does not change the existing array, but instead returns a new array. A plurality of arrays may be spliced 
// var new_array old_array.concat = ([VALUE1 [, value2 [, ... [, valueN]]]]) 
var arr2 is = [1,2,3,4,5] 
var ARR3 = [ 6,7,8,9,0] 
// the console.log (arr2.concat (ARR3)) // [1,2,3,4,5,6,7,8,9,0] 


// the Array .isArray () method to determine whether the value passed into an Array. 
Array.isArray ([. 1, 2,. 3]); // to true 
Array.isArray ({foo: 123}); // to false 
Array.isArray ( 'foobar'); // to false 
Array.isArray (undefined); / / to false 


// modify the value of the specified index alternative array (change the original array) returns the modified new array 
// arr.
// value populated with the values of the array. start index of the (optional). end end index (optional), the default is this.length. 
[. 1, 2,. 3] .fill (. 4); // [. 4,. 4,. 4] 
[. 1, 2,. 3] .fill (. 4,. 1); // [. 1,. 4,. 4] 
[. 1, 2 ,. 3] .fill (. 4,. 1, 2); // [. 1,. 4,. 3] 


// Flat () recursively to a specified depth array. The Flat () method to create a new array, the array of all child elements recursively connected to the specified depth. 
// var newArray = arr .flat ([ depth]); // depth ( optional) recursively to the default depth. 1 
var arr4 = [1,2, [3,4-]]; 
the console.log (arr4.flat ()) // [1,2,3,4] 
var arr5 = [1,2, [3,4-, [5,6]]]; 
the console.log (arr5.flat (2)) // [. 1 1,2,3,4,5,6] 


// includes the () method to retrieve an array of whether a particular entry comprises a value which returns true or false. 
// arr .includes (valueToFind [, fromIndex ]) // value valueToFind to search. fromIndex (optional) first of several default search from 0 
[. 1, 2,. 3] .includes (2); // to true 
[. 1, 2,. 3] .includes (. 4); // to false


// array summation reduce () accumulator value to the accumulated current value currentValue 
const arr6 = [. 1, 2,. 3,. 4]; 
const = the reducer (ACC with, currentValue) => + ACC with currentValue; 
//. 3. 1 + 2 + . 4 + 
the console.log (arr6.reduce (the reducer)); // 10 


if at least one detecting element through the // some () method to test an array 
// arr.some (callback (element [, index [, array ]]) [, thisArg]) 
var arr7 = [. 1, 2,. 3,. 4,. 5]; 
var = the even function (Element) { 
  return === Element 2; 
}; 
the console.log (arr7.some (the even) ); 


// toString () into the string array 
var array1 = [. 1, 2, 'A', '. 1A']; 
the console.log (array1.toString ()); // "1,2, A, 1a "

  

Guess you like

Origin www.cnblogs.com/-kuige/p/11095851.html