1.Array.map()

The map() method takes a function that iterates through all the items in the array and modifies them accordingly.

Const articles=[{id:0,title:' Les Miserables ',views:1258},{id:1,title:' Gone with the Wind ',views: 1280},{id:1,title:' To Live ',views: 1233}]

Based on the above array, get the array of all the titles, using the map method

Const titles=articles.map((item)=>item.title) // Output is [' Les Miserables ',' Gone with the Wind ',' Alive ']

2.Array.filter()

The filter() method is used to filter array elements

The filter() method fetches the elements of an array based on certain criteria and, like.map(), returns a new array, leaving the original array unchanged.

Based on the articles array above, get the arraylist whose views are less than 2000 and whose views are greater than 2000 respectively

Const less= item.filter ((item=>item.views<2000)) // [{id:0,title:' Les Misables ',views:1258},{id:1,title:' Gone with the Wind ',views:1580}] const much=articles.filter((item=>item.views>2000)) [{id:1,title:' alive ',views:2233}]

3.Array.forEach()

The forEach() method is much like a regular for loop, iterating through an array and executing a function on each element. The first argument to.foreach () is the callback function, which contains the current value and index of the loop array.

Item.foreach ((item,index)=>{console.log(' item.title} ')}) The title of index 0 is Les Miserables and the title of index 1 is Gone with the Wind and the title of index 2 is Alive.Copy the code

4.Array.every()

The.every() method checks if every element in the array passes the supplied condition, returning true if all elements in the array pass the condition, and false if not.

Check whether the views of articles array has more than 2000 articles

const over = articles.every((item) => item.views > 2000);
console.log(over); // true
Copy the code

5.Array.some()

The.some() method is similar to the.every() method, but validates the opposite, returning true if only one element in the array passes the condition, and false if all elements fail the condition.

Check articles to see if there are any articles with views over 3000

const isMore = articles.some((item) => item.views > 3000);
console.log(isMore);  // false

Copy the code