I have a String "SHELF-2-1-1-2-1", I need to remove "2" from that string and want the output to be "SHELF-1-1-2-1"
I tried:
var str = "SHELF-2-1-1-2-1";
var res = str.split("-");
How can I join the array to get "SHELF-1-1-2-1"?
This would work:
var str = "SHELF-2-1-1".split('-2').join('');
Sounds like you want to do a replace... Try:
var res = str.replace('-2', '');
"SHELF-2-10-20" into "SHELF-10-20". By default. replace only replaces the first occurrence. To perform a global replace, the first parameter needs to be a regular expression with the g flag applied.
2, or whatever character is in the 7th position? Will it always be a single character that is being removed, or will it sometimes be more than one character?str.replace("-2","")?