Underscore 互动版

在线工具推荐: Three.js AI纹理开发包 - YOLO合成数据生成器 - GLTF/GLB在线编辑 - 3D模型格式在线转换 - 可编程3D场景编辑器

keys 和 values

_.keys(object)

检索object拥有的所有可枚举属性的名称。

    _.keys({one: 1, two: 2, three: 3});
    => ["one", "two", "three"]

_.allKeys(object)

检索object拥有的和继承的所有属性的名称。

    function Stooge(name) {
      this.name = name;
    }
    Stooge.prototype.silly = true;
    _.allKeys(new Stooge("Moe"));
    => ["name", "silly"]

_.values(object)

返回object对象所有的属性值。

  _.values({one: 1, two: 2, three: 3});
  => [1, 2, 3]