我们有一个对象数组
var myArr = [ {name: "john", age:23, conflict:['booking', ' double booking']}
{name: "john", age:43, conflict:['booking', ' double booking']}
{name: "jim", age:101, conflict:['normal', ' double booking']}
{name: "bob", age:67, conflict:['cancelled', ' double booking']} ];
如何从myArr获取对象列表,其中的冲突对象在其中具有正常值?
答案 0 :(得分:0)
您可以使用filter
和find
来获取冲突数组中normal
的对象。
var myArr = [ {name: "john", age:23, conflict:['booking', ' double booking']},{name: "john", age:43, conflict:['booking', ' double booking']},{name: "jim", age:101, conflict:['normal', ' double booking']},{name: "bob", age:67, conflict:['cancelled', ' double booking']} ],
searchWord = 'normal';
var result = _.filter(myArr, function(o) {
return _.find(o.conflict, function(word) {
return word.toLowerCase() == searchWord.toLowerCase();
});
});
console.log(result);

<script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.4/lodash.min.js"></script>
&#13;