How to remove one character from string by index in JavaScript

2 Answers

0 votes
function removeAt(s, i) {
	return s.slice(0, i) + s.slice(i + 1);
}


let s = "javascript php c++";

s = removeAt(s, 2);

console.log(s);
 
 

 
/*
run:
 
jaascript php c++

*/

 



answered Jun 20, 2020 by avibootz
edited Jun 20, 2020 by avibootz
0 votes
function removeAt(s, i) {
	s = s.split('')
	s.splice(i, 1)

	return s.join('')
}

let s = "javascript php c++";

s = removeAt(s, 12);

console.log(s);
 
 

 
/*
run:
 
javascript pp c++

*/

 



answered Jun 20, 2020 by avibootz
edited Jun 20, 2020 by avibootz

Related questions

1 answer 155 views
1 answer 159 views
1 answer 164 views
1 answer 192 views
1 answer 108 views
1 answer 159 views
...