Consider the following example:
names = the let [ 'Lily', 'Barry', 'Dendi', 'Boogie', 'Lily' ]; the let nameNum = names.reduce ((pre, CUR) => { IF (CUR in pre) { // pre if there are attributes cur pre [cur] ++ ; } the else { pre [cur] =. 1 ; // add pre cur object attributes and assigned. 1 } return pre; }, {}) // the reduce () , for ES6 merge array method, where the initial value is set to a null object the console.log (nameNum); // {Barry:. 1, Boogie:. 1, Dendi:. 1, Lily: 2}
As can be seen, IF (key in obj) means obj whether there are key attributes, there is return to true , it does not return to false .