1. some In short: it checks each item in the array, and as long as one item passes, it is
Recently, I encountered a requirement when working on a backend management system: a The data structure is as follows, using let arr = [ { value: "apple" }, { value: "" }, { value: "banana" }, { value: "orange" }, { value: "" }, ] let res = arr.some(item=>{ return item.value !== "" }) console.log(res); Here, as long as there is a value, if (res) { console.log("array has value"); } else { console.log("Enter at least one value"); } 2. every In short: it checks each item in the array, and if any item fails it is let arr2 = [ { value: "apple" }, { value: "" }, { value: "banana" }, { value: "orange" }, { value: "er" }, ] var res2 = arr2.every(item => { return item.value !== "" }) console.log(res2); Here, as long as there is no value for one item, if (!res2) { //If res2 is true, then go to else; if it is false, then go to if console.log("The input box has an empty value"); } else { console.log("The input box has no empty value"); console.log("Proceed to the next step"); } 3. find From let arr3 = [ { value: "" }, { value: "" }, { value: "" }, { value: "" }, { value: "apple" }, ] var res3 = arr3.find(item => { return item.value !== "" }) console.log(res3); You can determine if (res3) { //res3 has a value, proceed to the next step here. console.log("There is at least one value in the array"); } else { //res3 is undefined console.log("The array is empty!"); } This is the end of this article about the details of using JS array methods some, You may also be interested in:
|
<<: MySQL complete collapse query regular matching detailed explanation
>>: How to use map to allow multiple domain names to cross domains in Nginx
Result:Implementation code: html <!-- Please h...
How to use CSS to control the arc movement of ele...
The previous article introduced the MySql multi-c...
MySQL partitioning is helpful for managing very l...
1. Modify the docker configuration file and open ...
I can log in to MYSQL normally under the command ...
1. Introduction to Linux .NET Core Microsoft has ...
1. Unzip to the location where you want to instal...
In react, if you modify the state directly using ...
Table of contents Why use day.js Moment.js Day.js...
XHTML Headings Overview When we write Word docume...
1. MYSQL index Index: A data structure that helps...
MySQL is now the database used by most companies ...
Application software generally has such business ...
There are three pages A, B, and C. Page A contains...