Socket
Book a DemoInstallSign in
Socket

arr

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

arr

Simple JavaScript utilities for working with arrays.

Source
npmnpm
Version
0.1.1
Version published
Weekly downloads
19
72.73%
Maintainers
1
Weekly downloads
 
Created
Source

arr NPM version

Simple JavaScript utilities for working with arrays.

Install

Install with npm:

npm i arr --save-dev

Usage

var utils = require('arr');

API

filterType

Filter array, returning only the values of the given type.

  • array {Array}
  • type {String}: Native type, e.g. string, object
  • returns: {Boolean}
var arr = ['a', {a: 'b'}, 1, 'b', 2, {c: 'd'}, 'c'];

utils.filterType(arr, 'object');
//=> [{a: 'b'}, {c: 'd'}]

numbers

  • array {Array}
  • index {Array}: Optionally specify the index of the number to return, otherwise all numbers are returned.
  • returns: {Array}

Filter array, returning only the numbers.

strings

  • array {Array}
  • index {Array}: Optionally specify the index of the string to return, otherwise all strings are returned.
  • returns: {Array}

Filter array, returning only the strings.

objects

  • array {Array}
  • index {Array}: Optionally specify the index of the object to return, otherwise all objects are returned.
  • returns: {Array}

Filter array, returning only the objects.

functions

  • array {Array}
  • index {Array}: Optionally specify the index of the function to return, otherwise all functions are returned.
  • returns: {Array}

Filter array, returning only the functions.

arrays

  • array {Array}
  • index {Array}: Optionally specify the index of the array to return, otherwise all arrays are returned.
  • returns: {Array}

Filter array, returning only the arrays.

first

  • array {Array}
  • returns: {*}

Get the first element in array. Included for completeness.

last

  • array {Array}
  • returns: {*}

Get the last element in array.

lastOfType

Get the last element in array of the given type.

  • array {Array}
  • type {String}: The native type to get.
  • returns: {*}
var arr = ['a', {a: 'b'}, 1, 'b', 2, {c: 'd'}, 'c'];
lastOfType(arr, 'number');
//=> 2

firstOfType

Get the first element in array of the given type.

  • array {Array}
  • type {String}: The native type to get.
  • returns: {*}
var arr = ['a', {a: 'b'}, 1, 'b', 2, {c: 'd'}, 'c'];
firstOfType(arr, 'number');
//=> 1

lastIsType

Returns true if the last element in array is the given type.

  • array {Array}
  • type {String}: The native type to check.
  • returns: {Boolean}
var arr = ['a', {a: 'b'}, 1, 'b', 2, {c: 'd'}, 'c'];
lastIsType(arr, 'number');
//=> false

firstIsType

Returns true if the first element in array is the given type.

  • array {Array}
  • type {String}: The native type to check.
  • returns: {Boolean}
var arr = ['a', {a: 'b'}, 1, 'b', 2, {c: 'd'}, 'c'];
firstIsType(arr, 'string');
//=> true

firstString

Get the first string in array.

  • array {Array}
  • returns: {String}
var arr = ['a', {a: 'b'}, 1, 'b', 2, {c: 'd'}, 'c'];
firstString(arr, 'string');
//=> 'a'

lastString

Get the last string in array.

  • array {Array}
  • returns: {String}
var arr = ['a', {a: 'b'}, 1, 'b', 2, {c: 'd'}, 'c'];
lastString(arr, 'string');
//=> 'c'

firstFunction

Get the first function in array.

  • array {Array}
  • returns: {Function}
var arr = ['a', {a: 'b'}, 1, 'b', 2, {c: 'd'}, 'c'];
firstFunction(arr, 'function');
//=> 'a'

lastFunction

Get the last function in array.

  • array {Array}
  • returns: {Function}
var arr = ['a', {a: 'b'}, 1, 'b', 2, {c: 'd'}, 'c'];
lastFunction(arr, 'function');
//=> 'a'

firstNumber

Get the first number in array.

  • array {Array}
  • returns: {Function}
var arr = ['a', {a: 'b'}, 1, 'b', 2, {c: 'd'}, 'c'];
firstNumber(arr, 'number');
//=> '1'

lastNumber

Get the last number in array.

  • array {Array}
  • returns: {Function}
var arr = ['a', {a: 'b'}, 1, 'b', 2, {c: 'd'}, 'c'];
lastNumber(arr, 'number');
//=> '2'

firstObject

Get the first object in array.

  • array {Array}
  • returns: {Object}
var arr = ['a', {a: 'b'}, 1, 'b', 2, {c: 'd'}, 'c'];
firstObject(arr);
//=> {a: 'b'}

lastObject

Get the last object in array.

  • array {Array}
  • returns: {Object}
var arr = ['a', {a: 'b'}, 1, 'b', 2, {c: 'd'}, 'c'];
lastObject(arr);
//=> {c: 'd'}

Author

Jon Schlinkert

License

Copyright (c) 2014 Jon Schlinkert, contributors.
Released under the MIT license

This file was generated by verb-cli on September 30, 2014.

Keywords

array

FAQs

Package last updated on 30 Sep 2014

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