or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

index.md
tile.json

tessl/npm-lodash--keysin

The lodash method keysIn exported as a module for creating arrays of own and inherited enumerable property names.

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
npmpkg:npm/lodash.keysin@4.2.x

To install, run

npx @tessl/cli install tessl/npm-lodash--keysin@4.2.0

index.mddocs/

Lodash KeysIn

The 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.

Package Information

  • Package Name: lodash.keysin
  • Package Type: npm
  • Language: JavaScript
  • Installation: npm install lodash.keysin

Core Imports

const keysIn = require('lodash.keysin');

ES6 modules:

import keysIn from 'lodash.keysin';

Basic Usage

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']

Capabilities

KeysIn Function

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 query

Returns:

  • (Array): Returns the array of property names

Behavior:

  • Coerces non-object values to objects using Object(object)
  • Iterates through all enumerable properties in the object and its prototype chain
  • Filters out certain internal properties:
    • 'constructor' property on prototypes when not explicitly set
    • Array-like 'length' property in specific contexts to avoid duplicates with numeric indices
  • Returns an array containing all qualifying property names
  • Property iteration order is not guaranteed

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);
// => []