Detailed description of the every () method in JavaScript, javascriptevery

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.