1. Every ()

Function: Checks whether all elements in an array match a specified condition. (all)

Description:

If one element in the array is detected as unqualified, the entire expression returns false, the remaining elements are not tested, and true is returned if all elements are unqualified.

Note:

You need to pass in a function that returns a value of type BOOLen.

Parameters:

array.every(function(value, index, arr))

First argument: the element of the array

Second argument: the index of the array

Third argument: the entire array

Code:

// Check to see if everyone in the class has passed

const user = [
    {name : 'bill'.js : 89},
    {name : 'Cathy'.js : 77},
    {name : 'the horse 6'.js : 55}];const result = user.every((value) = > value.js >= 60);
console.log(result);Copy the code



2. some() method:

Function: Checks whether any element in an array matches a specified condition. (part)

Description:

If one element in the array is detected, the entire expression returns true, the rest of the elements are not tested, and if none of the elements meet the criteria, false is returned.

Note:

You need to pass in a function that returns a value of type BOOLen.

Parameters:

array.some(function(value, index, arr))

First argument: the element of the array

Second argument: the index of the array

Third argument: the entire array

Code:

// Check if there are any illegal keywords

let words = ['Wahaha'.'Fruit orange'];
let title = 'Fruit orange is delicious.';

let state = words.some(value= > title.indexOf(value) >= 0);
if(state) console.log('Title contains offending keywords');Copy the code


3. Filter () method:

Function: Filter elements in data.

Description:

Creates a new array whose elements meet the criteria by referring to all the elements in the specified array.

Note:

You need to pass in a function that returns a value of type BOOLen.

Parameters:

array.some(function(value, index, arr))

First argument: the element of the array

Second argument: the index of the array

Third argument: the entire array

Code:

let lessons = [
    {title : 'mathematics'.teacher : 'Miss Li'},
    {title : 'English'.teacher : 'Miss Wang'},
    {title : 'sports'.teacher : 'Miss Li'}];let teacherLiClass = lessons.filter(value= > value.teacher == 'Miss Li');
console.log(teacherLiClass);Copy the code


4. Map () method:

Action: Applied to each element of an array to map new values.

Description:

By specifying a function to process each element of the array, and return the array after processing, the original array and the new array for a mapping relationship.

Note:

The function needs to be passed in and the function returns the new value.

Parameters:

array.some(function(value, index, arr))

First argument: the element of the array

Second argument: the index of the array

Third argument: the entire array

Code:

let lessons = [
    {title : 'mathematics'.teacher : 'Miss Li'},
    {title : 'English'.teacher : 'Miss Wang'},
    {title : 'sports'.teacher : 'Miss Li'}]; lessons = lessons.map(item= > {
    item.title = '[Grade 3]${item.title}`;
    return item;
});
console.log(lessons);Copy the code