in操作符

// Arrays,数组:下标 in array,length也可以

var trees = new Array("redwood", "bay", "cedar", "oak", "maple");

0 in trees        // returns true

3 in trees        // returns true

6 in trees        // returns false

"bay" in trees    // returns false (you must specify the 

                  // index number, not the value at that index)

"length" in trees // returns true (length is an Array property)

 

// Predefined objects:内置对象

"PI" in Math          // returns true

 

// Custom objects:对象,key in obj

var mycar = {make: "Honda", model: "Accord", year: 1998};

"make" in mycar  // returns true

"model" in mycar // returns true

 

//使用字符串对象构造的

var color1 = new String("green");

"length" in color1 // returns true 

//string不会使用构造函数转换

var color2 = "coral";

// generates an error (color2 is not a String object)

"length" in color2

 

//delete之后,就false了

var mycar = {make: "Honda", model: "Accord", year: 1998};

delete mycar.make;

"make" in mycar;  // returns false 

var trees = new Array("redwood", "bay", "cedar", "oak", "maple");

delete trees[3];

3 in trees; // returns false

 

//设为undefined的话,就false

var mycar = {make: "Honda", model: "Accord", year: 1998};

mycar.make = undefined;

"make" in mycar;  // returns true 

var trees = new Array("redwood", "bay", "cedar", "oak", "maple");

trees[3] = undefined;

3 in trees; // returns true

 

//可以找到原型链的key

"toString" in {}; // returns true

原文地址:https://www.cnblogs.com/wang-jing/p/4736436.html