zoukankan      html  css  js  c++  java
  • 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

  • 相关阅读:
    js例子
    js表单验证
    Python之Numpy的基础及进阶函数(图文)
    Numpy库的下载及安装(吐血总结)
    世界,你好!
    用逻辑回归模型解决互联网金融信用风险问题
    用逻辑回归模型解决互联网金融信用风险问题
    如何建立投资模型
    如何建立投资模型
    秒懂数据类型的真谛—Python基础前传(4)
  • 原文地址:https://www.cnblogs.com/wang-jing/p/4736436.html
Copyright © 2011-2022 走看看