Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

deep-for-each

Package Overview
Dependencies
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

deep-for-each

Recursively iterates over arrays and objects

  • 3.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
139K
increased by9.6%
Maintainers
1
Weekly downloads
 
Created

What is deep-for-each?

The deep-for-each npm package allows you to iterate over all the properties of an object or elements of an array, including nested ones. This is particularly useful for performing operations on deeply nested structures without having to manually traverse each level.

What are deep-for-each's main functionalities?

Iterate over all properties of a nested object

This feature allows you to iterate over all properties of a nested object, including those within nested objects and arrays. The callback function provides the value, key, subject, and path of each property.

const deepForEach = require('deep-for-each');

const obj = {
  a: 1,
  b: { c: 2, d: { e: 3 } },
  f: [4, 5, { g: 6 }]
};

deepForEach(obj, (value, key, subject, path) => {
  console.log(`Key: ${key}, Value: ${value}, Path: ${path}`);
});

Modify properties of a nested object

This feature allows you to modify the properties of a nested object. In this example, all numeric values are doubled.

const deepForEach = require('deep-for-each');

const obj = {
  a: 1,
  b: { c: 2, d: { e: 3 } },
  f: [4, 5, { g: 6 }]
};

deepForEach(obj, (value, key, subject) => {
  if (typeof value === 'number') {
    subject[key] = value * 2;
  }
});

console.log(obj);

Other packages similar to deep-for-each

Keywords

FAQs

Package last updated on 13 Mar 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc