zoukankan      html  css  js  c++  java
  • Object.keys()

    Object.keys(obj),返回一个数组,数组里是该obj可被枚举的所有属性名。请看示例:

    示例一:

    function Pasta(grain, width, shape) {
        this.grain = grain;
        this.width = width;
        this.shape = shape;
        this.toString = function () {
            return (this.grain + ", " + this.width + ", " + this.shape);
        }
    }
    
    console.log(Object.keys(Pasta)); //console: []
    var spaghetti = new Pasta("wheat", 0.2, "circle");
    console.log(Object.keys(spaghetti)); //console: ["grain", "width", "shape", "toString"]

    示例二:

    var arr = ["a", "b", "c"];
    console.log(Object.keys(arr)); // console: ["0", "1", "2"]
    
    
    var obj = {0: "a", 1: "b", 2: "c"};
    console.log(Object.keys(obj)); // console: ["0", "1", "2"]
    
    
    var an_obj = {100: "a", 2: "b", 7: "c"};
    console.log(Object.keys(an_obj)); // console: ["2", "7", "100"]
  • 相关阅读:
    hh
    SDUT 3923 打字
    最短路
    阶乘后面0的个数(51Nod 1003)
    大数加法
    Biorhythms(中国剩余定理)
    usaco-5.1-theme-passed
    usaco-5.1-starry-passed
    usaco-5.1-fc-passed
    usaco-4.4-frameup-passed
  • 原文地址:https://www.cnblogs.com/maqunjing/p/5367170.html
Copyright © 2011-2022 走看看