简体   繁体   English

Javascript array.find 对象按属性值

[英]Javascript array.find object by property value

a) Is there any difference between the methods bellow (performance wise)? a)以下方法之间有什么区别(性能方面)?

b) Does this (.find) function iterates over all objects in the array? b) 这个 (.find) 函数是否遍历数组中的所有对象?

c) Is there yet another syntax for this function? c) 这个函数还有另一种语法吗?

#1 console.log(cres.find(o => o.name === refname));

#2 console.log(cres.find(function(o){return o.name===refname;}));

I'm looking for the most efficient way to find an object by it's property value in a large array.我正在寻找通过大型数组中的属性值查找对象的最有效方法。 So, implementing a custom function (Ie:BTREE) would be a better approach?那么,实现自定义函数(即:BTREE)会是更好的方法吗?

Thx谢谢

UPDATE: Besides the "down vote".更新:除了“否决票”。 I've learned that the case in #1 is just a fancy notation for functions (Es6).我了解到 #1 中的案例只是函数的一种花哨的表示法 (Es6)。 So basically both cases are the same.所以基本上两种情况都是一样的。

Anyways, It does not explains if the .find function iterates over all objects in the array and if that's the case a custom implementation would be more performatic...无论如何,它没有解释 .find 函数是否遍历数组中的所有对象,如果是这种情况,自定义实现会更高效......

a) / c) There is no difference, option 1 is just using ES6 syntax. a) / c) 没有区别,选项 1 只是使用 ES6 语法。 You can checkout the docs here: http://es6-features.org/#ExpressionBodies您可以在此处查看文档: http : //es6-features.org/#ExpressionBodies

b) .find will iterate over the array until it finds a result then it will stop. b) .find将遍历数组,直到找到结果然后停止。 Reference 参考

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM