array

Methods

(static) concat(object, path, …arrays) → {Object}

Source:
Since:
  • 0.2.0
See:
Replaces an array concatenating the former array with additional arrays and/or values.
⚠ Due to name conflicts, this function is named arrayConcat when imported from top level (import { arrayConcat } from 'immutadot').
Example
concat({ nested: { prop: [1, 2] } }, 'nested.prop', [3, 4]) // => { nested: { prop: [1, 2, 3, 4] } }
Parameters:
Name Type Attributes Description
object Object The object to modify.
path Array | string The path of the property to set.
arrays Array
repeatable
The arrays to concatenate.
Returns:
Returns the updated object.
Type
Object

(static) fill(object, path, value, [start], [end]) → {Object}

Source:
Since:
  • 0.3.0
See:
Replaces by an array filled with value from start up to, but not including, end.
Example
fill({ nested: { prop: [1, 2, 3, 4] } }, 'nested.prop', 6, 1, 3) // => { nested: { prop: [1, 6, 6, 4] } }
Parameters:
Name Type Attributes Default Description
object Object The object to modify.
path Array | string The path of the property to set.
value * The value to fill array with.
start number
optional
0
end number
optional
array.length
Returns:
Returns the updated object.
Type
Object

(static) filter(object, path, predicate) → {Object}

Source:
Since:
  • 1.0.0
See:
Replaces by an array of elements predicate returns truthy for.
Example
filter({ nested: { prop: [1, 2, 3, 4] } }, 'nested.prop', v => v % 2) // => { nested: { prop: [1, 3] } }
Parameters:
Name Type Description
object Object The object to modify.
path Array | string The path of the property to set.
predicate function The function invoked per iteration.
Returns:
Returns the updated object.
Type
Object

(static) map(object, path, callback) → {Object}

Source:
Since:
  • 1.0.0
See:
Replaces by an array of values by running each element in the former collection thru callback.
Example
map({ nested: { prop: [1, 2, 3] } }, 'nested.prop', v => v * 2) // => { nested: { prop: [2, 4, 6] } }
Parameters:
Name Type Description
object Object The object to modify.
path Array | string The path of the property to set.
callback function The function invoked per iteration.
Returns:
Returns the updated object.
Type
Object

(static) pop(object, path) → {Object}

Source:
Since:
  • 1.0.0
See:
Replaces by an array of elements with last element removed.
Example
pop({ nested: { prop: [1, 2, 3, 4] } }, 'nested.prop') // => { nested: { prop: [1, 2, 3] } }
Parameters:
Name Type Description
object Object The object to modify.
path Array | string The path of the property to set.
Returns:
Returns the updated object.
Type
Object

(static) push(object, path, …values) → {Object}

Source:
Since:
  • 0.1.7
See:
Replaces an array adding one or more elements to the end of the former array.
Examples

Add one element.

push({ nested: { prop: [1, 2] } }, 'nested.prop', 3) // => { nested: { prop: [1, 2, 3] } }

Add several elements.

push({ nested: { prop: [1, 2] } }, 'nested.prop', 3, 4) // => { nested: { prop: [1, 2, 3, 4] } }
Parameters:
Name Type Attributes Description
object Object The object to modify.
path Array | string The path of the property to set.
values *
repeatable
The values to add.
Returns:
Returns the updated object.
Type
Object

(static) reverse(object, path) → {Object}

Source:
Since:
  • 0.3.0
See:
Replaces an array reversing the elements from the former array.
Example
reverse({ nested: { prop: [1, 2, 3] } }, 'nested.prop') // => { nested: { prop: [3, 2, 1] } }
Parameters:
Name Type Description
object Object The object to modify.
path Array | string The path of the property to set.
Returns:
Returns the updated object.
Type
Object

(static) shift(object, path) → {Object}

Source:
Since:
  • 1.0.0
See:
Replaces by an array of elements with first element removed.
Example
shift({ nested: { prop: [1, 2, 3, 4] } }, 'nested.prop') // => { nested: { prop: [2, 3, 4] } }
Parameters:
Name Type Description
object Object The object to modify.
path Array | string The path of the property to set.
Returns:
Returns the updated object.
Type
Object

(static) slice(object, path, [start], [end]) → {Object}

Source:
Since:
  • 0.3.0
See:
Replaces an array by a slice of the former array from start up to, but not including, end.
⚠ Due to name conflicts, this function is named arraySlice when imported from top level (import { arraySlice } from 'immutadot').
Example
slice({ nested: { prop: [1, 2, 3, 4] } }, 'nested.prop', 1, 3) // => { nested: { prop: [2, 3] } }
Parameters:
Name Type Attributes Default Description
object Object The object to modify.
path Array | string The path of the property to set.
start number
optional
0 The start position.
end number
optional
array.length The end position.
Returns:
Returns the updated object.
Type
Object

(static) sort(object, path, comparatornullable) → {Object}

Source:
Since:
  • 1.0.0
See:
Replaces by a sorted array, in natural order or according to the optional comparator.
Examples
sort({ nested: { prop: [2, 4, 3, 1] } }, 'nested.prop') // => { nested: { prop: [1, 2, 3, 4] } }
sort({ nested: { prop: [2, 4, 3, 1] } }, 'nested.prop', (a, b) => b - a) // => { nested: { prop: [4, 3, 2, 1] } }
Parameters:
Name Type Attributes Description
object Object The object to modify.
path Array | string The path of the property to set.
comparator function
nullable
The comparator function.
Returns:
Returns the updated object.
Type
Object

(static) splice(object, path, start, [deleteCount], …values) → {Object}

Source:
Since:
  • 0.2.0
See:
Replaces an array removing and/or adding elements at index in the former array.
Example
splice({ nested: { prop: [1, 2, 3, 4] } }, 'nested.prop', 1, 2, 5, 6) // => { nested: { prop: [1, 5, 6, 4] } }
Parameters:
Name Type Attributes Description
object Object The object to modify.
path Array | string The path of the property to set.
start number Index at which to start changing the array.
deleteCount number
optional
The number of old array elements to remove.
values *
repeatable
The values to add.
Returns:
Returns the updated object.
Type
Object

(static) unshift(object, path, …values) → {Object}

Source:
Since:
  • 0.1.7
See:
Replaces an array adding elements at the start of the former array.
Examples

Add one element.

unshift({ nested: { prop: [1, 2] } }, 'nested.prop', 3) // => { nested: { prop: [3, 1, 2] } }

Add several elements.

unshift({ nested: { prop: [1, 2] } }, 'nested.prop', 3, 4) // => { nested: { prop: [3, 4, 1, 2] } }
Parameters:
Name Type Attributes Description
object Object The object to modify.
path Array | string The path of the property to set.
values *
repeatable
The values to add.
Returns:
Returns the updated object.
Type
Object