• The objKeys() method returns an array of a given object's own enumerable property names, iterated in the same order that a normal loop would.

    objKeys() returns an array whose elements are strings corresponding to the enumerable properties found directly upon object. The ordering of the properties is the same as that given by looping over the properties of the object manually.

    Parameters

    • value: any

      The object to obtain a copy of the keys from

    Returns string[]

    An array of the properties names for the value object.

    Example

    // simple array
    const arr = ['a', 'b', 'c'];
    console.log(objKeys(arr)); // console: ['0', '1', '2']

    // array-like object
    const obj = { 0: 'a', 1: 'b', 2: 'c' };
    console.log(objKeys(obj)); // console: ['0', '1', '2']

    // array-like object with random key ordering
    const anObj = { 100: 'a', 2: 'b', 7: 'c' };
    console.log(objKeys(anObj)); // console: ['2', '7', '100']

    // getFoo is a property which isn't enumerable
    const myObj = objCreate({}, {
    getFoo: {
    value() { return this.foo; }
    }
    });
    myObj.foo = 1;
    console.log(objKeys(myObj)); // console: ['foo']