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

array-split

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

array-split

split an array into multiple arrays using a predicate, with results keyed within an object

  • 1.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
42
increased by16.67%
Maintainers
1
Weekly downloads
 
Created
Source

array-split

What does it do?

Splits an array into multiple arrays using a predicate function. returns an object containing the results keyed based on the return value of the predicate function.

How do I use it?

Example: Separate odd and even numbers

const split  = require('array-split');

const numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9];

const result = split(numbers, (num) => {
  if (num % 2 === 0) return 'even';
  return 'odd';
});

This will return...

{
  even: [2, 4, 6, 8],
  odd: [1, 3, 5, 7, 9]
}

Anything else?

The predicate function only supports returning types... null, undefined, string or number

  • If you return null or undefined the value is dropped from the result set.
  • If you return a string or a number, it is keyed in the results object (numbers are converted to strings)

FAQs

Package last updated on 23 May 2017

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