Javascript array every method tests whether all the elements in an array passes the test implemented by the provided function.
Its syntax is as follows −
array.every(callback[, thisObject]);
callback − Function to test for each element.
thisObject − Object to use as this when executing callback.
Returns true if every element in this array satisfies the provided testing function.
This method is a JavaScript extension to the ECMA-262 standard; as such it may not be present in other implementations of the standard. To make it work, you need to add the following code at the top of your script.
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; }; }
Try the following example.