delete character from string javascript code example

Example 1: how to remove lasr char from string in javascript

str=str.slice(0, -1);

Example 2: js remove string from string

var ret = "data-123".replace('data-','');
console.log(ret);   //prints: 123

Example 3: javascript remove character from string

mystring.replace(/r/g, '')

Example 4: delate char betwen index js

// First find the substring of the string to replace, then replace the first occurrence of that string with the empty string.

S = S.replace(S.substring(bindex, eindex), "");

//Another way is to convert the string to an array, splice out the unwanted part and convert to string again.

var result = S.split("");
result.splice(bindex, eindex - bindex);
S = result.join("");