Skip to content

keys

js
_.keys(object)

创建 object 自身可枚举属性名称的数组。

¥Creates an array of the own enumerable property names of object.

注意:非对象值被强制转换为对象。有关更多详细信息,请参阅 ES 规范

¥Note: Non-object values are coerced to objects. See the ES spec for more details.

新增于

¥Since

0.1.0

参数

¥Arguments

  1. object (对象):的反面;

    ¥object (Object): The object to query.

返回

¥Returns

(数组):返回属性名称的数组。

¥(Array): Returns the array of property names.

示例

¥Example

js
function Foo() {
  this.a = 1;
  this.b = 2;
}

Foo.prototype.c = 3;

_.keys(new Foo);
// => ['a', 'b'] (iteration order is not guaranteed)

_.keys('hi');
// => ['0', '1']

Lodash v4.17 中文网 - 粤ICP备13048890号