array.insert [method]
array.insert( int pos, ... )
inserts the variables passed (all arguments after first) to the position specified in the array or emits a warning on failure (index out of bounds), returns the array for chaining
pos
accepts both positive and negative values, the meaning is "which value to insert before"
- negative values are converted to positive ones by adding (<size> + 1) to them
- beginning of array can be inserted to using position 0 or (- <size> - 1)
- end of array can be inserted to using position <size> or -1
a = [ 5, 7 ];
a.insert( 1, 6 ); // inserts 6 at position 1 (before item with index 1)
a.insert( -1, 8 ); // appends to the end of array, a = [5,6,7,8] now