New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

dimensionality

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

dimensionality

Find the number of dimensions of an array

latest
Source
npmnpm
Version
1.0.1
Version published
Maintainers
1
Created
Source

dimensionality

Find the number of dimensions of an array

npm install dimensionality --save

Usage

dimensionality(array[, shallowSearch = false])

Returns the maximum array depth of the array, meaning the maximum number of nests in the nested arrays.

var dimensionality = require('dimensionality');

dimensionality(undefined) // 0
dimensionality(4) // 0
dimensionality([2, 4, 5, 2]) // 1
dimensionality([undefined, null, 2, {}, 'test']) // 1
dimensionality([undefined, null, 2, {}, 'test', []]) // 2
dimensionality([[{}, ['test']]]) // 3
dimensionality([1, [2, [3, [4]]]]) // 4

// shallowSearch example
dimensionality([[4, [5]]]) // 3
dimensionality([[4, [5]]], true) // 2
dimensionality([
  [[1, 2], [3, 4]],
  [[5, 6], [7, 8]],
], true) // 3

ShallowSearch

By default, shallowSearch = false.

If shallowSearch = true, then dimensionality finds the dimension only searching for the first element of the nested array.

This is useful for large data structures that are known to have equal array depth.

Keywords

array

FAQs

Package last updated on 06 Jan 2015

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