Options
All
  • Public
  • Public/Protected
  • All
Menu

Interface ObjectForEachOptions

Hierarchy

  • ObjectForEachOptions

Index

Properties

notOwn?: boolean | -1
passDescriptor?: boolean

If true, then the callback function takes an element descriptor instead of a value

default

false

example
Object.forEach({a: 1}, {showDescriptor: true}, (el) => {
// {configurable: true, enumerable: true, writable: true, value: 1}
console.log(el);
});
propsToIterate?: "all" | "own" | "inherited"

Strategy to iterate object properties:

  1. 'own' - the object iterates only own properties (by default)
  2. 'inherited' - the object iterates only inherited properties (for-in with the negative hasOwnProperty check)
  1. 'all' - the object iterates inherited properties too (for-in without the hasOwnProperty check)
example
const obj = {a: 1, __proto__: {b: 2}};

Object.forEach(obj, (el) => {
console.log(el); // 1
});

Object.forEach(obj, {propsToIterate: 'all'}, (el) => {
console.log(el); // 1 2
});

Object.forEach(obj, {propsToIterate: 'inherited'}, (el) => {
console.log(el); // 2
});
withDescriptor?: boolean
withNonEnumerables?: boolean

If true, the function will iterate all object properties, but not only enumerable. Non-enumerable properties from a prototype are ignored.

default

false

example
const obj = {a: 1};

Object.defineProperty(obj, 'b', {value: 2});

// 1
// 2
Object.forEach(obj, {withNonEnumerables: true}, (el) => {
console.log(el);
});