js basics-common array object methods (two)

1. entries(). Returns an iterative object of an array, which contains the key/value pairs of the array.
Note: According to the returned object, call the next().value method to obtain an array
of key-value pairs.

var m=['111','222','333'];
var x=m.entries();
console.log(x.next().value);
console.log(x.next().value);
console.log(x.next().value);

Console output
Insert picture description here
2. Every() detects whether all elements of the array meet the specified conditions (provided by the function)

array.every(function(currentValue,index,arr), thisValue)
  • Will not detect empty arrays
  • Does not change the original array
  • Return true or false All matches return true otherwise return false

3. filter(). Create a new array, the elements of the new array are checked and passed the specified array to meet the conditions (do not change the original array)

array.filter(function(currentValue,index,arr),thisvalue)
  • Do not change the original array
  • What is returned is a new array composed of eligible elements
    Insert picture description here

4. find(). Returns the value of the first element of the tested array that meets the conditions (without changing the original array)

array.find(function(currentValue,index,arr), thisValue)

Example
Insert picture description here
5. findIndex(). Return the value of the first element of the tested array that meets the conditions (do not change the original array)

array.findIndex(function(currentValue,index,arr), thisValue)

Example
Insert picture description here
6. Each element of the forEach() array executes the callback function
Insert picture description here
7. includes(). Determine whether an array contains a specified value

arr.includes(searchElement, fromIndex)

Example
Insert picture description here

8. map(). The function processes each element in the array and returns the processed array

  • Process the elements in sequence according to the original array order
  • Will not change the original array
  • Will not detect empty arrays

Insert picture description here
9. some(). Check whether the elements in the array meet the specified conditions

  • Execute each element in the array in turn, if one meets the condition, it returns true, and only if all does not meet the condition, it returns false
  • Do not change the original array
  • Do not check for empty arrays
    Insert picture description here

Iterable object

遍历器(interator)是一种接口,为各种数据类型提供统一的访问机制。任何数据接口只要部署Interator,就可以完成遍历操作。
遍历过程创建一个指针对象,调用指针的next方法,每调用一次next()方法就会返回value和done两个属性对象,value是当前成员的值,done是一个布尔值表示循环可以结束。

The data structure with native Iterator is

Array /map/set/string/typedArray/函数的arguments对象/nodeList对象

Guess you like

Origin blog.csdn.net/qq_40969782/article/details/115296813