keysIn
object
Creates an array of the own and inherited enumerable property names of object.
Installation
Import
import { keysIn } from '@tulx/utils';Source Code
Implementation
/**
* Creates an array of the own and inherited enumerable property names of object.
*
* @param object - The object to query.
* @returns Returns the array of property names.
*
* @example
* ```ts
* function Foo() {
* this.a = 1;
* this.b = 2;
* }
* Foo.prototype.c = 3;
* keysIn(new Foo()); // ['a', 'b', 'c']
* ```
*/
export function keysIn(object: Record<string, unknown>): string[] {
const result: string[] = [];
for (const key in object) {
result.push(key);
}
return result;
}
Example
import { keysIn } from '@tulx/utils';
function Foo() {
this.a = 1;
this.b = 2;
}
Foo.prototype.c = 3;
keysIn(new Foo()); // ['a', 'b', 'c']Related Functions
assign
Assigns own enumerable string keyed properties of source objects to the destination object.
assignIn
This method is like assign except that it iterates over own and inherited source properties.
assignInWith
This method is like assignIn except that it accepts customizer which is invoked to produce the assigned values.
assignWith
This method is like assign except that it accepts customizer which is invoked to produce the assigned values.
at
Creates an array of values corresponding to paths of object.
create
Creates an object that inherits from the prototype object.