Free for PREMIUM members
var str = "one:two:three:four:five:six"
var arrayStr = str.split(":");
var n = 3; //the position of the item you want to replace
var newItem="apple"; //the value you want to go into the nth position
arrayStr[n-1] = newItem; //using n-1 because arrays start at 0, not 1
var newStr = arrayStr.join(":")
Open in new window
Please enter a first name
Please enter a last name
Must be at least 4 characters long.
Join and Comment
From novice to tech pro — start learning today.
Premium members can enroll in this course at no extra cost.
Premium members get this course for $159.20.
Premium members get this course for $95.20.
Premium members get this course for $87.50.
Premium members get this course for $62.50.