Array methods

Built-in array manipulation: splice for removing and inserting elements in place.

mJS arrays support in-place editing with splice(). (Iteration uses plain for loops or for(let i in arr)for..of is not part of mJS.)

Functions

array.splice()

a.splice(start, deleteCount, [item1, item2, …])

Changes the contents of an array by removing existing elements and/or inserting new ones.

Arguments

NameTypeRequiredDefaultDescription
start number yes Index at which to start changing the array.
deleteCount number yes How many elements to remove from start.
items… any optional Elements to insert at start.

Example

let a = [1,2,3,4,5];
a.splice(1, 2, 100, 101, 102);
// a === [1,100,101,102,4,5]