我有对象数组,我想使用 _.each 方法访问该对象的属性 运行良好
var x = [{id:1, name:"xyz"},{id:2, name:"pqr"},...and so on]
我正在使用 _.each 方法访问
_.each(x ,function(param){console.log("id:" + param.Id +" and name:"+ param.name);});
我只想显示 x 的前 5 个 我怎样才能做到这一点?
谢谢
最佳答案
您可以在使用_.each()
之前使用_.first()
获取前5个...
_.each(_.first(x, 5) ,function(param){console.log("id:" + param.Id +" and name:"+ param.name);});
关于javascript - UnderscoreJS : Getting only top 5 using the _. 每个方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22828772/