or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

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

0

# lodash.forown

1

2

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.

3

4

## Package Information

5

6

- **Package Name**: lodash.forown

7

- **Package Type**: npm

8

- **Language**: JavaScript

9

- **Installation**: `npm install lodash.forown`

10

11

## Core Imports

12

13

```javascript

14

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

15

```

16

17

For ES6+ environments (using CommonJS interop):

18

19

```javascript

20

import forOwn from 'lodash.forown';

21

```

22

23

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

24

25

## Basic Usage

26

27

```javascript

28

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

29

30

// Basic object iteration

31

var obj = { 'a': 1, 'b': 2, 'c': 3 };

32

forOwn(obj, function(value, key) {

33

console.log(key + ': ' + value);

34

});

35

// => logs 'a: 1', 'b: 2', 'c: 3' (iteration order is not guaranteed)

36

37

// Early exit by returning false

38

var users = {

39

'fred': { 'user': 'fred', 'active': false },

40

'barney': { 'user': 'barney', 'active': true }

41

};

42

43

forOwn(users, function(value, key) {

44

console.log(key);

45

if (key === 'fred') {

46

return false; // Exit iteration early

47

}

48

});

49

// => logs 'fred' only

50

51

// Using with context binding

52

function Logger(prefix) {

53

this.prefix = prefix;

54

}

55

56

Logger.prototype.log = function(value, key) {

57

console.log(this.prefix + key + ': ' + value);

58

};

59

60

var logger = new Logger('[LOG] ');

61

forOwn({ 'a': 1, 'b': 2 }, logger.log, logger);

62

// => logs '[LOG] a: 1', '[LOG] b: 2'

63

```

64

65

## Capabilities

66

67

### Object Property Iteration

68

69

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

70

71

```javascript { .api }

72

/**

73

* Iterates over own enumerable properties of an object invoking `iteratee`

74

* for each property. The `iteratee` is bound to `thisArg` and invoked with

75

* three arguments: (value, key, object). Iteratee functions may exit iteration

76

* early by explicitly returning `false`.

77

*

78

* @param {Object} object The object to iterate over.

79

* @param {Function} [iteratee] The function invoked per iteration.

80

* @param {*} [thisArg] The `this` binding of `iteratee`.

81

* @returns {Object} Returns `object`.

82

*/

83

function forOwn(object, iteratee, thisArg)

84

```

85

86

**Parameters:**

87

- `object` (Object): The object to iterate over

88

- `iteratee` (Function, optional): The function invoked per iteration. Receives three arguments: `(value, key, object)`. Defaults to identity function if not provided

89

- `thisArg` (*, optional): The `this` binding context for the iteratee function

90

91

**Returns:**

92

- (Object): Returns the original `object` parameter

93

94

**Key Features:**

95

- Only iterates over **own** enumerable properties (not inherited properties)

96

- Iteratee receives three arguments: value, key, and the original object

97

- Supports early exit by returning `false` from the iteratee

98

- Optional context binding via `thisArg` parameter

99

- Returns the original object for potential chaining

100

101

**Usage Examples:**

102

103

```javascript

104

// Simple property logging

105

var data = { name: 'John', age: 30, city: 'NYC' };

106

forOwn(data, function(value, key, obj) {

107

console.log('Property ' + key + ' has value ' + value);

108

});

109

110

// Conditional processing with early exit

111

var config = { debug: true, verbose: false, production: true };

112

forOwn(config, function(value, key) {

113

if (value === true) {

114

console.log('Enabled: ' + key);

115

if (key === 'production') {

116

return false; // Stop processing after finding production

117

}

118

}

119

});

120

121

// Object transformation (modifying original object)

122

var scores = { alice: '95', bob: '87', charlie: '92' };

123

forOwn(scores, function(value, key, obj) {

124

obj[key] = parseInt(value); // Convert strings to numbers

125

});

126

// scores is now { alice: 95, bob: 87, charlie: 92 }

127

```

128

129

## Implementation Notes

130

131

- This package is part of the modularized lodash ecosystem

132

- Dependencies: `lodash._basefor`, `lodash._bindcallback`, `lodash.keys`

133

- CommonJS module only (no ES6 module support)

134

- Iteration order is not guaranteed (depends on JavaScript engine implementation)

135

- Only processes own enumerable properties (excludes inherited and non-enumerable properties)

136

- Compatible with objects, arrays, and other enumerable structures