+ 1

Can someone clarify how the splice() JavaScript Function works?

I have been trying to remove a character from a String in JavaScript but I can't seem to get it right... I recently saw on a blog that there are three ways to remove characters and one of them was through using the splice() JavaScript function but I didn't quite understand how to use it. Kindly help me clarify.

17th Apr 2021, 9:28 PM
Njoroge Kenneth Michuki
Njoroge Kenneth Michuki - avatar
2 Réponses
+ 1
What I know is that the splice() function only works with arrays Where you give the index of the element as a parameter and it takes care of the rest
17th Apr 2021, 9:50 PM
Khalil Galalem
Khalil Galalem - avatar
+ 1
You can concatenate the two parts of the string surrounding the character like str = str.slice(0, i) + str.slice(i+1) Where i is the index of your character
17th Apr 2021, 9:42 PM
Khalil Galalem
Khalil Galalem - avatar