javascript - split string in two on given index and return both parts -
i have string need split on given index , return both parts, seperated comma. example:
string: 8211 = 8,211 98700 = 98,700
so need able split string on given index , return both halves of string. built in methods seem perform split return 1 part of split.
string.slice return extracted part of string. string.split allows split on character not index string.substring need returns substring string.substr similar - still returns substring
try
function splitvalue(value, index) { return value.substring(0, index) + "," + value.substring(index); } console.log(splitvalue("3123124", 2));
Comments
Post a Comment