JS the map, some, every method

 Brief introduction

  every () method is used to detect whether all elements in an array meet the specified criteria, if they meet the return true, otherwise return false; will not empty array detection, does not change the original array.

  some () method for detecting whether there are elements in the array satisfies a specified condition, if yes returns true, otherwise returns false; not empty array detector, does not alter the array.

  map () method returns a new array, a new array for each element calls a function value corresponding to the processing of each element in the original array; not edit the empty array, the array does not alter.


1、every()

  grammar

  array.every(function(item,index,array){})  

  // item: the value of the current element;

  // index: the index of the current element;

  // array: an array of objects of the current element;

  example

// array of values used in greater than 10 
var AGEs = [ 32 , 33 is , 12 is , 40 ];
 var Age ages.every = ((Val, IND) => {
    return Val> 10 ; 
}) 
the console.log (Age ) // to true

2、some()

  grammar

  array.some(function(item,index,array){})  

  // item: the value of the current element;

  // index: the index of the current element;

  // array: an array of objects of the current element;

  example

// array values are greater than the present 35 
var AGEs = [ 32 , 33 is , 12 is , 40 ];
 var Age ages.every = ((Val, IND) => {
    return Val> 35 ; 
}) 
the console.log (Age) // to true

3、some()

  grammar

  array.map(function(item,index,array){})  

  // item: the value of the current element;

  // index: the index of the current element;

  // array: an array of objects of the current element;

  example      

// for each value of the original array are square 
var Numbers = [ 2 , . 3 , . 4 , . 5 ];
 var  Double = numbers.map ((Val, IND) => {
    return Val * Val 
}); 
the console.log ( Double ) // [. 4,. 9, 16, 25]

 

Guess you like

Origin www.cnblogs.com/aidixie/p/11284327.html