PP.arrInsertBefore

Syntax

arrInsertBefore(arr: Array, o, toInsert);

Parameters

arr. Array of elements.

toInsert. Element before which the new element will be inserted.

o. Element to be inserted to the array.

Description

The arrInsertBefore method inserts an element into array before the selected element.

Comments

This method returns True if element is successfully inserted into the array, or new size of this array (a Number type value) if the element after which a new element must be inserted, is not found.

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 arrays of integer numbers
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 inserting the element: " + 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