在lodash集合中使用variables名称

问题有点疯狂。 有没有可能使用variables名而不是另一个,显然,考虑下面的代码,我必须相应地切换到任何variables名“人”或“学生”

var people=[ {name:"akash",age:25}, {name:"abi",age:22} ]; var student =[ {name:"Sanjai",age:25}, {name:"Ravi",age:35}, {name:"Bopara",age:36} ]; var variables=["people","student"]; var result= _.find(variables[0], function(o) { return o.age < 35; }); console.log(result); 

       

网上收集的解决方案 "在lodash集合中使用variables名称"

当然,只要将variables放入数组而不是string:

 var variables=[people, student]; 

完整的例子:

 var people=[ {name:"akash",age:25}, {name:"abi",age:22} ]; var student =[ {name:"Sanjai",age:25}, {name:"Ravi",age:35}, {name:"Bopara",age:36} ]; var variables=[people, student]; var result= _.find(variables[0], function(o) { return o.age < 35; }); console.log(result); 
 <script src="https://cdn.jsdelivr.net/lodash/4.17.4/lodash.min.js"></script>