or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

index.md
tile.json

tessl/npm-lodash--keys

The modern build of lodash's _.keys as a module for creating arrays of own enumerable property names.

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

To install, run

npx @tessl/cli install tessl/npm-lodash--keys@3.1.0

index.mddocs/

Lodash Keys

Lodash Keys is a modularized version of lodash's _.keys functionality that creates an array of the own enumerable property names of an object. It provides a robust implementation with cross-browser compatibility and fallback support for environments without native Object.keys.

Package Information

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

Core Imports

var keys = require('lodash.keys');

For ES modules environments:

import keys from 'lodash.keys';

Basic Usage

var keys = require('lodash.keys');

// Get keys from a plain object
var obj = { 'a': 1, 'b': 2, 'c': 3 };
console.log(keys(obj)); // => ['a', 'b', 'c'] (iteration order is not guaranteed)

// Works with constructor functions
function Foo() {
  this.a = 1;
  this.b = 2;
}
Foo.prototype.c = 3;
console.log(keys(new Foo)); // => ['a', 'b'] (excludes inherited properties)

// Handles string objects
console.log(keys('hi')); // => ['0', '1']

// Returns empty array for null/undefined
console.log(keys(null)); // => []
console.log(keys(undefined)); // => []

Capabilities

Object Keys Extraction

Creates an array of the own enumerable property names of an object, excluding inherited properties.

/**
 * Creates an array of the own 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 keys(object);

Key Features:

  • Uses native Object.keys when available and appropriate
  • Falls back to custom implementation for special cases (prototype objects, array-like objects)
  • Handles non-object values by coercing them to objects
  • Excludes inherited properties (own properties only)
  • Cross-browser compatible with fallbacks for older environments

Usage Examples:

var keys = require('lodash.keys');

// Plain objects
keys({ 'name': 'John', 'age': 30 }); // => ['name', 'age']

// Arrays (returns string indices)
keys(['a', 'b', 'c']); // => ['0', '1', '2']

// Strings (returns character indices)
keys('hello'); // => ['0', '1', '2', '3', '4']

// Constructor instances (excludes prototype properties)
function Person() {
  this.name = 'John';
  this.age = 30;
}
Person.prototype.species = 'human';
keys(new Person()); // => ['name', 'age']

// Array-like objects
var arrayLike = { '0': 'a', '1': 'b', 'length': 2 };
keys(arrayLike); // => ['0', '1', 'length']

// Edge cases
keys(null); // => []
keys(undefined); // => []
keys(42); // => [] (number coerced to Number object)
keys(true); // => [] (boolean coerced to Boolean object)

Browser Compatibility

  • Works in all modern browsers with native Object.keys support
  • Includes fallback implementation for older browsers (IE8 and below)
  • Handles various JavaScript engine quirks and edge cases
  • Optimized for performance using native methods when available

Dependencies

This package depends on other modularized lodash utilities:

  • lodash._getnative (^3.0.0): For getting native method references
  • lodash.isarguments (^3.0.0): For detecting arguments objects
  • lodash.isarray (^3.0.0): For detecting arrays

These dependencies are automatically installed and provide specialized functionality for robust object property enumeration across different JavaScript environments.