PP.insertToArr

Syntax

insertToArr(arr: Array, item, index: Number);

Parameters

arr. Initial array of elements.

item. Element to be inserted to the array.

index. Element before which the new element is inserted.

Description

The insertToArr method inserts an element into array before a specified element.

Comments

This method returns True if the element is successfully inserted into array, otherwise it returns False.

Example

To execute the example, add a link to PP.js scenario file to HTML page. Determine an array of integers and insert a new value before one of the elements:

// Determine an integer array
var numbers = [5, 9, 6, 7, 2];
console.log("Source array: " + numbers);
// Insert the 0 value before the 6 element
PP.arrInsertBefore(numbers, 0, 6);
console.log("Array after the element is inserted into it: " + numbers);

After executing the example the value 0 is inserted into the initial array before the element 6:

Initial array: 5,9,6,7,2
Array after element insertion: 5,9,0,6,7,2

See also:

PP