Skip to content

ObjectConstructor.each method

ObjectConstructor › each

Official

Check if all properties in an object satisfy a condition.

Signature:

each(object: Record<string, T>, callback: (value: T, key?: string | undefined) => boolean | void, context?: unknown): boolean

Parameters:

Parameter Type Description
object Record<string, T> The object to check.
callback (value: T, key?: string | undefined) => boolean | void The condition to check.
context? unknown The context passed as this to the callback.

Returns: booleantrue if all properties satisfy the condition, false otherwise.

Example:

console.log(Object.each({ a: 1, b: 2 }, function(value) { return value > this.min }, { min: 0 })); // true
console.log(Object.each({ a: 1, b: 2 }, function(value) { return value > this.min }, { min: 1 }); // false