Alga.js
  • Introduction
  • Installation
  • Array
    • $.array.insert
    • $.array.update
    • $.array.destroy
    • $.array.select
    • $.array.hidden
    • $.array.search
    • $.array.filter
    • $.array.paginate
    • $.array.sort
    • $.array.setOperations
    • $.array.sum
    • $.array.calculate
  • Object
    • $.object.remove
  • String & Char
    • $string.split
    • $.char.random
  • Number (Int & Float)
    • $.number.calc
    • $.number.currency
  • Date
    • $.date.now
    • $.date.format
    • $.date.parse
    • $.date.days
    • $.date.weeks
    • $.date.months
    • $date.calendar
Powered by GitBook
On this page

Was this helpful?

  1. Array

$.array.insert

Insert method of array helpers

Insert is an array method from array helper that we use to inject or add the data into a new array. We create this method as a function closure, so we can use spread parameter and can be insert multiple data at the same time.

Insert data at the first element of array

$.array.insert(fromArray, atObject, ...allValues*)
//atObject={position: 'first', index: 0} last, before or after

//or
$.array.insertFirst(fromArray, ...allValues*)

// Example:
const fromArray = ['item 1', 'item 2']
$.array.insertFirst(fromArray, 'item 3')
//=> ['item 3', 'item 1', 'item 2']

//or
$.array.insert(fromArray, {position: 'first'}, 'new item')

Insert data at the last element of array

$.array.insertLast(fromArray, ...allValues*)

// Example:
$.array.insertLast(fromArray, 'item 3')
//=> ['item 1', 'item 2', 'item 3']

//or
$.array.insert(fromArray, {position: 'last'}, 'new item')

Insert data before any element by index

$.array.insertBefore(fromArray, beforeIndex, ...allValues*)

// Example:
$.array.insertBefore(fromArray, 2, 'new text')

//or
$.array.insert(fromArray, {position: 'before', index: 2}, 'new item')

Insert data after any element by index

$.array.insertAfter(fromArray, afterIndex, ...allValues*)

// Example:
$.array.insertAfter(fromArray, 2, 'new text')

//or
$.array.insert(fromArray, {position: 'after', index: 2}, 'new item')

Insert multiple data to the array

$.array.insertFirst(fromArray, 'text', 1, {}, [])

//or
$.array.insertLast(fromArray, 'string', 1.5, {'key': 'value'}, [])
PreviousInstallationNext$.array.update

Last updated 3 years ago

Was this helpful?