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

array-walker

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

array-walker

Multi-dimensional array walker with observation

  • 1.0.0
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

Array Walker

Traverses a multi-dimensional array and fires off a callback with a value and its relationship.

Example

let walker = require('array-walker');

// A single-dimensional array
walker(['a', 'b'], (value, key) => console.log(value, key));
// a, 0
// b, 1

// A two-dimensional array
walker([['a', 'b'], ['c', 'd']], (value, x, y) => console.log(value, x, y));
// a, 0, 0
// b, 0, 1
// c, 1, 0
// d, 1, 1

// A 12-dimensional array
walker(
  [[[[[[[[[[[['a', 'b']]]]]], 'c']]]]]],
  (value, ...lineage) => console.log(value, ...lineage)
);
// a, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
// b, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1
// c, 0, 0, 0, 0, 0, 1

Installation

$ npm install array-walker

API

var walker = require('array-walker');

walker(items, observationCallback, ...lineage)

TypeData TypeNameDescription
parameter*[]itemsThe array to walk.
parameterfunctionobservationCallbackThe function to call when a non-array value is found.
parameter...number[lineage]The parent indexes.
returnsundefinedn/an/a

observationCallback(value, ...lineage)

The observation callback is fired when a non-array value is found.

TypeData TypeNameDescription
parameter!*[]valueThe value that was discovered.
parameter...numberlineageThe indexes in each dimension of the array.
returnsundefinedn/an/a
  • Github: array-walker

Keywords

FAQs

Package last updated on 29 Jun 2016

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