.insert(location,val)

Description

Insert is a method that puts a value into a string, object or an array at a location

Parameters

Insert takes the location to insert a value and the value to insert as parameters.

Usage On Arrays

arr = ["wow"]
// setup the array

log arr.insert(1,"hello world")
// returns ["hello world","wow"]
// "hello world" was inserted at index one

Usage On Strings

str = "1 2 4 5 6"
// setup the string

str.insert(4," 3 ")
// update the variable and prepend the value to the start of the string
// fixes the sequence

log str
// returns "1 2 3 4 5 6"

Usage On Objects

obj = {}
// setup the object

obj.insert("key","value")
// update the object

log obj
// returns {"key":"value"}

Last updated