Get the App
SLTechnology News&Howtos  ›  Development  › 

The operation method of iterating every and some in JavaScript array

Shulou Source: shulou.com Published: 2022-06-01 09:35:18 10月15日 Update

This article mainly introduces the JavaScript array iteration every and some of the operation methods related knowledge, detailed and easy to understand, simple and fast operation, with a certain reference value, I believe that everyone will read this JavaScript array iteration every and some of the operation methods of the article will have some gains, let's take a look at it.

Array.every()

The every () method checks whether all array values pass the test.

This example checks if all array values are greater than 18:

examples

var numbers = [45, 4, 9, 16, 25];

var allOver18 = numbers.every(myFunction);

function myFunction(value, index, array) {

return value > 18;

}

Note that this function takes three parameters:

item value

item index

array itself

If the callback function uses only the first parameter (value), the other parameters can be omitted:

examples

var numbers = [45, 4, 9, 16, 25];

var allOver18 = numbers.every(myFunction);

function myFunction(value) {

return value > 18;

}

Array.some()

Some () methods check whether certain array values pass the test.

This example checks if certain array values are greater than 18:

examples

var numbers = [45, 4, 9, 16, 25];

var someOver18 = numbers.some(myFunction);

function myFunction(value, index, array) {

return value > 18;

}

Note that this function takes three parameters:

item value

item index

array itself

All browsers support Array.some (), except Internet Explorer 8 or earlier.

About "JavaScript array iteration every and some of the operation methods" The content of this article is introduced here, thank you for reading! I believe that everyone has a certain understanding of the knowledge of "JavaScript array iteration every and some operation methods". If you still want to learn more knowledge, please pay attention to the industry information channel.

Tags: Array method iteration parameter project check function instance knowledge example content article index test value easy to operate article easy to understand more browser Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MySQL Shulou Technology Huawei vpn Microsoft