define

The object.keys () method returns an array containing all the Object’s own enumerable property names.

grammar

Object.keys(obj);

parameter

Obj: The object to get the free attribute name

The return value

An array containing all of the object’s own enumerable property names. Attribute that does not include Symbol value.

Example 1: Get the object property name

var obj = {
    a: 1.b: 2.c: 3[Symbol('d')]: 4
}
Object.keys(obj);
//["a", "b", "c"]
Copy the code

Example 2: Get non-object property values

var str = 'abcd';
Object.keys(str);
//["0", "1", "2", "3"] casts to an object, returns an array of object subscripts.
Copy the code