Find all objects with matching Ids javascript

送分小仙女□ 提交于 2019-11-29 12:27:39

I would look into the filter function. It's build into JavaScript.

Here's an example of how it works. All you need to do is find a way to make a function that will tell if it has the proper id.

function isBigEnough(value) {
  return value >= 10;
}
var filtered = [12, 5, 8, 130, 44].filter(isBigEnough);
// filtered is [12, 130, 44]

If you see the documentation for _.find it states

Iterates over elements of collection, returning the first element predicate returns truthy for.


You should use the _.filter method for what you want

Iterates over elements of collection, returning an array of all elements predicate returns truthy for.

Something like

const result = _.filter(students, {student_id: studentId});
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!