javascript - Get characters in string at positions [1] and [2] -
i know can 1 character of string giving .charat()
index position of character.
but there method can give range (e.g. position 1
position 2
) , respective characters?
use substring().
var str = "hello world!"; var res = str.substring(1, 5); //'ello' result
if want chars, split
, array.
arr = res.split('') //["e", "l", "l", "o"] result
Comments
Post a Comment