【发布时间】:2017-05-10 09:00:42
【问题描述】:
如果找到three,那么它应该返回true并停止迭代。否则返回 false 如果没有找到。
我正在使用filter() - 使用方法是否错误?
var data = [
'one',
'two',
'three',
'four',
'three',
'five',
];
found = data.filter(function(x) {
console.log(x);
return x == "three";
});
console.log(found);
【问题讨论】:
-
filter()方法,对数组中的每一项运行 give 函数,并返回该函数返回 true 的所有项的数组;有用的链接:coderwall.com/p/_ggh2w/… -
使用
filter没有错,但是你可以使用.find()来满足你的要求...相关:stackoverflow.com/questions/23614054/…
标签: javascript