or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

index.md
tile.json

tessl/npm-lodash--forown

The modern build of lodash's forOwn function for iterating over own enumerable object properties.

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

To install, run

npx @tessl/cli install tessl/npm-lodash--forown@3.0.0

index.mddocs/

lodash.forown

The modern build of lodash's forOwn function as a standalone module for iterating over own enumerable properties of objects. This modularized version allows you to include only the specific lodash functionality you need, reducing bundle size and improving performance.

Package Information

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

Core Imports

var forOwn = require('lodash.forown');

For ES6+ environments (using CommonJS interop):

import forOwn from 'lodash.forown';

Note: This package is CommonJS only and does not provide native ES6 module exports.

Basic Usage

var forOwn = require('lodash.forown');

// Basic object iteration
var obj = { 'a': 1, 'b': 2, 'c': 3 };
forOwn(obj, function(value, key) {
  console.log(key + ': ' + value);
});
// => logs 'a: 1', 'b: 2', 'c: 3' (iteration order is not guaranteed)

// Early exit by returning false
var users = {
  'fred': { 'user': 'fred', 'active': false },
  'barney': { 'user': 'barney', 'active': true }
};

forOwn(users, function(value, key) {
  console.log(key);
  if (key === 'fred') {
    return false; // Exit iteration early
  }
});
// => logs 'fred' only

// Using with context binding
function Logger(prefix) {
  this.prefix = prefix;
}

Logger.prototype.log = function(value, key) {
  console.log(this.prefix + key + ': ' + value);
};

var logger = new Logger('[LOG] ');
forOwn({ 'a': 1, 'b': 2 }, logger.log, logger);
// => logs '[LOG] a: 1', '[LOG] b: 2'

Capabilities

Object Property Iteration

Iterates over own enumerable properties of an object, invoking an iteratee function for each property.

/**
 * Iterates over own enumerable properties of an object invoking `iteratee`
 * for each property. The `iteratee` is bound to `thisArg` and invoked with
 * three arguments: (value, key, object). Iteratee functions may exit iteration
 * early by explicitly returning `false`.
 *
 * @param {Object} object The object to iterate over.
 * @param {Function} [iteratee] The function invoked per iteration.
 * @param {*} [thisArg] The `this` binding of `iteratee`.
 * @returns {Object} Returns `object`.
 */
function forOwn(object, iteratee, thisArg)

Parameters:

  • object (Object): The object to iterate over
  • iteratee (Function, optional): The function invoked per iteration. Receives three arguments: (value, key, object). Defaults to identity function if not provided
  • thisArg (*, optional): The this binding context for the iteratee function

Returns:

  • (Object): Returns the original object parameter

Key Features:

  • Only iterates over own enumerable properties (not inherited properties)
  • Iteratee receives three arguments: value, key, and the original object
  • Supports early exit by returning false from the iteratee
  • Optional context binding via thisArg parameter
  • Returns the original object for potential chaining

Usage Examples:

// Simple property logging
var data = { name: 'John', age: 30, city: 'NYC' };
forOwn(data, function(value, key, obj) {
  console.log('Property ' + key + ' has value ' + value);
});

// Conditional processing with early exit
var config = { debug: true, verbose: false, production: true };
forOwn(config, function(value, key) {
  if (value === true) {
    console.log('Enabled: ' + key);
    if (key === 'production') {
      return false; // Stop processing after finding production
    }
  }
});

// Object transformation (modifying original object)
var scores = { alice: '95', bob: '87', charlie: '92' };
forOwn(scores, function(value, key, obj) {
  obj[key] = parseInt(value); // Convert strings to numbers
});
// scores is now { alice: 95, bob: 87, charlie: 92 }

Implementation Notes

  • This package is part of the modularized lodash ecosystem
  • Dependencies: lodash._basefor, lodash._bindcallback, lodash.keys
  • CommonJS module only (no ES6 module support)
  • Iteration order is not guaranteed (depends on JavaScript engine implementation)
  • Only processes own enumerable properties (excludes inherited and non-enumerable properties)
  • Compatible with objects, arrays, and other enumerable structures