var str = “Sample”;
Now you can access individual characters in a String, just like an array
alert(str[2]); // returns ‘m’
and even apply some array functions on it.
alert(Array.prototype.join.call(str, ",") // returns S,a,m,p,l,e,
Note: While applying array functions on the String, remember that the string is behaving like read-only array. So functions that manipulate the string won’t work!
Tweet
No comments:
Post a Comment