Method ES6 Array (Find)

There are an array of objects found eligible subjects (find methods After finding the object is not qualified to perform in the future) without qualifying returns undefined
        var ARR = [ 
            {name: 'Jerry', Sex: 'man' }, 
            {name: 'Jack', Sex: 'Woman' }, 
            {name: 'Jack', Sex: 'man' } 
        ] 
        var Jack = ARR .find ( function (obj) {
             return obj.name == 'Jack' ; 
        }) 
        the console.log (Jack);   // returns first object qualified {name: "jack", sex : "woman"} 

        var Bill = arr.find ( function (obj) {
             return obj.name == 'Bill' ; 
        }) 
        Console.  log(bill);  // undefined

 

Guess you like

Origin www.cnblogs.com/webmc/p/11586584.html