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

init-array

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

init-array

Creates new array with defined size and initial value

  • 1.2.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

init-array

NPM version

Creates new array with defined size and initial value

Install

npm install --save init-array

Usage

Arguments:

  • dimensions
  • value to assign
var newArray = require('init-array');

newArray(3);            // [ 0, 0, 0 ]
newArray(1, 256);       // [ 256 ]
newArray([3, 2]);       // [ [ 0, 0 ], [ 0, 0 ], [ 0, 0 ] ]
newArray([2], 'test');  // [ 'test', 'test' ]
newArray([2, 3], 1);    // [ [ 1, 1, 1 ], [ 1, 1, 1 ] ]
// etc

If value argument is function then executes this function for each element.

newArray(3, Math.random);   // [ 0.5508887629402555, 0.7256682864214947, 0.8916228685296357 ]

var i = 0;
initArray([2,2], () => i++) // [ [ 0, 1 ], [ 2, 3 ] ]

Testing

npm test

Keywords

FAQs

Package last updated on 27 Apr 2018

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