+ 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.
2 odpowiedzi
+ 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
+ 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