Remove character at specific index from string in JavaScript
Given a string value, remove the character at specific index from the string.
Solution
To remove a character at specific index from the given string in JavaScript, use String.substr()
method. Get the substring that is prior to the index, and the substring after the index. Join these two substrings.
str.substr(0, index - 1) + str.substr(index)
Program
1. Remove character at index=8
from the string str
.
let str = 'helloworld';
let index = 8;
let output = str.substr(0, index - 1) + str.substr(index);
console.log(output);