2021年3月9日星期二

Is there a way to filter an array with specific number of returned items in JS?

For example, I only want to get two items that satisfy the filter condition.

filter() then slice(2) will iterate all items which is really a waste while find() can only return one item.

Is there any way to specify the number of returned items that satisfy the filter condition? except writing for loop by myself.

https://stackoverflow.com/questions/66557260/is-there-a-way-to-filter-an-array-with-specific-number-of-returned-items-in-js March 10, 2021 at 09:46AM

没有评论:

发表评论