JavaScript Code

How to remove character at specific index from string?


Problem Statement

given a string, 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

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);