utilizes.push
TypeScript icon, indicating that this package has built-in type declarations

1.2.2 • Public • Published

push

Push safely to array. returning the length of the array - if the item pushed successfully.

Usage: push(object, pathToArray, ...items): number

import { push } from 'utilizes.push'

{ /*example for using with array that inside an object */

    const ob = {}

    push(ob, 'path.to.arr', 'item1', 'item2')
    // Output: 2
    console.log(ob.path.to.arr)
    // Output: ['item1', 'item2']

}
{/*example for using on simple array that attempt to be exist */

    let arr: any[] = null

    push(arr, 'item')
    // Output: undefined
    arr = []

    push(arr, 'item')
    // Output: 1

}

This module exported from utilizes project.

Readme

Keywords

Package Sidebar

Install

npm i utilizes.push

Weekly Downloads

0

Version

1.2.2

License

MIT

Unpacked Size

54.1 kB

Total Files

5

Last publish

Collaborators

  • natqe3