+ 8
Grabbing the first character of the input field value.
In the below code how can I grab the first character of the input field and do something with it(I want to create a list item with that character in the Dom) I had log the the whole value of the input field but I want only the first character. https://code.sololearn.com/WVPOwF9RB5Bm/?ref=app
3 Réponses
+ 5
You can get first character with adding [0] after variable name.
You can change line 4 like below code to get first charachter:
returnVal = input.value[0];
0
Use charAt() method which accepts a number. It's a position of a character. Positioning starts from zero.