ES6 study notes (9)-usage of in

usage:

1. Object judgment

Determine if there is this variable or method in the object

let obj = {
    a:2,
    b:5,
    c:6
}
 
console.log('a' in obj);

2. Array judgment

Mainly judge whether there is a value in the subscript of the array, whether it is empty, the following two examples illustrate

let arr = ['web', 'c ++', 'java', 'javascript' ]; 
 
console.log ( 1 in arr); // Subscript 1 has value, so output TRUE
let arr = ['web' ,, 'java', 'javascript' ]; 
 
console.log ( 1 in arr); // Subscript 1 has no value, so output false

The above is the usage of in!

Guess you like

Origin www.cnblogs.com/pwindy/p/12695968.html