Some,every,map,filter in JavaScript is used only with Each,eachlimit,map,maplimit,filter in ANSYC

Source: Internet
Author: User

var t = [1,2,3,4,5];

Some does not continue after it finds the first qualifying value in the array
Used to determine if the values in the array meet the requirements, and return the result True|false
function return type is BOOL
var some = T.some (function (item) {if (item% 2 = = = 0) {return true;} else{return false;}});
Console.log (some);

Every matches every element until there is a return of false
function return type is Boolean
var every = T.every (function (item) {if (item% 2!== 0) {return true;} else{Console.log (item); return false;});
Console.log (every);

Map handles all values in the array and returns the processed value without affecting the original array, returning the result to the new array
function return type of item
var map = T.map (function (item) {return item + 1;});
Console.log (map);

Filter array element Filters, returns true to the collection into a new array, returns the result as a new array
function return type is BOOL
var filter = T.filter (function (item) {if (item% 2 = = = 0) {return true;} else{return false;}});
Console.log (filter);

Console.log ('------------------------');
Async.eachlimit (t, 2, function (item, CB) {
Console.log ("Each limit item=" + item);
CB ();
}, function (err) {
Console.log ("End .....");
});

Async.map (t, function (item, CB) {
Console.log ("Map item =" + Item);
CB ();
}, function (err) {
Console.log ("End ...");
});
Async.maplimit (t, 2, function (item, CB) {
Console.log ("Map Limit item =" + Item);
CB ();
}, function (err) {
Console.log ("End ...");
});
Async.filter (t, function (item, CB) {
if (item% 2 = = = 0) {
CB (TRUE);
}else{
CB (FALSE);
}
}, function (Result) {
Console.log (result);
});

Some,every,map,filter in JavaScript is used only with Each,eachlimit,map,maplimit,filter in ANSYC

Related Article

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.