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
IT issues often require a personalized solution. With Ask the Experts™, submit your questions to our certified professionals and receive unlimited, customized solutions that work for you.
Take hold of your future.