The lodash method keysIn exported as a module for creating arrays of own and inherited enumerable property names.
npx @tessl/cli install tessl/npm-lodash--keysin@4.2.0The lodash method _.keysIn exported as a module that creates an array of the own and inherited enumerable property names of an object. This utility function is essential for deep object inspection and property enumeration across inheritance chains.
npm install lodash.keysinconst keysIn = require('lodash.keysin');ES6 modules:
import keysIn from 'lodash.keysin';import keysIn from 'lodash.keysin';
// Simple object
keysIn({ 'a': 1, 'b': 2, 'c': 3 });
// => ['a', 'b', 'c']
// Object with inherited properties
function Foo() {
this.a = 1;
this.b = 2;
}
Foo.prototype.c = 3;
keysIn(new Foo);
// => ['a', 'b', 'c'] (iteration order is not guaranteed)
// Arrays
keysIn([1, 2, 3]);
// => ['0', '1', '2']
// Non-object values are coerced to objects
keysIn('hello');
// => ['0', '1', '2', '3', '4']Creates an array of the own and inherited enumerable property names of object.
/**
* Creates an array of the own and inherited enumerable property names of object.
* Non-object values are coerced to objects.
*
* @param {Object} object The object to query.
* @returns {Array} Returns the array of property names.
*/
function keysIn(object);Parameters:
object (Object): The object to queryReturns:
Array): Returns the array of property namesBehavior:
Object(object)Usage Examples:
// Object with prototype chain
function Animal(name) {
this.name = name;
}
Animal.prototype.species = 'unknown';
Animal.prototype.speak = function() {};
const dog = new Animal('Rex');
dog.breed = 'German Shepherd';
keysIn(dog);
// => ['name', 'breed', 'species', 'speak']
// Array-like objects
const arrayLike = { 0: 'a', 1: 'b', length: 2 };
keysIn(arrayLike);
// => ['0', '1', 'length']
// Primitive values
keysIn(42);
// => []
keysIn('test');
// => ['0', '1', '2', '3']
keysIn(true);
// => []