In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-05 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly introduces "what is the function of javascript every () method". In daily operation, I believe that many people have doubts about the function of javascript every () method. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful for you to answer the doubts about "what is the use of javascript every () method?" Next, please follow the editor to study!
In javascript, the every () method is used to detect whether all elements of the array meet the specified condition (provided by the callback function), with the syntax "array.every (function (currentValue,index,arr), thisValue)".
The operating environment of this tutorial: windows7 system, javascript1.8.5 version, Dell G3 computer.
The every () method is used to detect whether all elements of the array meet the specified condition (provided by the callback function).
The every () method detects all the elements in the array using the specified function:
If an element is detected in the array that is not satisfied, the entire expression returns false, and the remaining elements are no longer detected.
Returns true if all elements meet the condition.
Syntax:
Array.every (function (currentValue,index,arr), thisValue)
Parameters:
Function (currentValue, index,arr): a callbackfn function that cannot be omitted and can accept up to three parameters:
Value: the value of the current array element, which cannot be omitted.
Index: the numeric index of the current array elements.
Array: the array object to which the current element belongs.
ThisValue: optional. Object is used as the callback for this execution, passed to the function and used as the value of "this". If thisValue is omitted, the value of "this" is "undefined".
The every () method calls the callbackfn function on each array element once in ascending order until the callbackfn function returns false. If the element that causes callbackfn to return false is found, the every () method returns false; immediately. Otherwise, the every () method returns true. The every () method does not call the callback function for missing elements in the array.
Except for array objects, the every () method can be used by any object that has a length property with its own numerically indexed property name, such as associative array objects, Arguments, and so on.
Example 1
The following example detects whether the elements in the array are all even and prompts.
Function f (value, index, ar) {if (value% 2 = = 0) {return true;} else {return false;}} var a = [2mai 4je 5je 6jing8]; if (a.every (f)) {console.log ("all even");} else {console.log ("not all even");}
Example 2
The following example detects whether the value of the element in the array is within the specified range. The range value is set by an object. Use this example to demonstrate the use of the thisArg parameter.
Var f = function (value) {if (typrof value! = = 'number') {return false;} else {return value > = this.min & & value
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.