2017-09-27 9 views
0

에서 필터 우리는 충돌 객체가 정상적인 값이 어디 인 myArr에서 개체 목록을 얻는 방법 Loadash : 배열 객체

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']} ]; 

같은

같은 개체의 배열을 가지고?

답변

0

filterfind을 사용하면 충돌 배열에 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>