Detailed description of the every () method in JavaScript, javascriptevery
Each method in the JavaScript array tests whether all elements in the array have passed the provided functions.
Syntax
array.every(callback[, thisObject]);
The following is the detailed information about the parameters:
- Callback: The function is used to test each element.
- ThisObject: the object used for executing the callback
Return Value:
Returns true if each element in the array meets the provided test function.
Compatibility:
This method is a JavaScript extension to the ECMA-262 standard; so it may not exist in other implementations of the standard. To make it work, you need to add the following script code at the top:
if (!Array.prototype.every){ Array.prototype.every = function(fun /*, thisp*/) { var len = this.length; if (typeof fun != "function") throw new TypeError(); var thisp = arguments[1]; for (var i = 0; i < len; i++) { if (i in this && !fun.call(thisp, this[i], i, this)) return false; } return true; };}
Example:
This produces the following results:
First Test Value : falseSecond Test Value : true