Array.insert

Array.insert

Array.insert

Function

Inserts one or more elements at the specified index.

Syntax

Parameters

ParametersTypeRequiredDefault valueDescription
indexIntNo0Insertion position; negative numbers are counted backward from the tail, and if they exceed the boundary, they will be caught at the array boundary.
valueNAnyNoNoneThe element to insert.

Return value

TypeDescription
ArrayReturns the original array object to facilitate continued chain calls.

Example

Notes

  • insert will modify the original array.
  • When you only need to insert elements, insert is more intuitive than splice(index, 0, value).