+ 1
How to convert string into array?
Language: Javascript If you have a string such as var a = "Sololearn" can you convert it into an array like "s" "o" "l", etc? If not how can you manipulate a string to work as an array?
2 Respuestas
+ 7
var a = [].slice.call("Sololearn");//I mostly use this way
//or
var a = "Sololearn".split('');//Mostly used in people
//or
var a = Array.from("Sololearn");
//Not end yet :P
//or even with
[].map.call("Sololearn",function(i){return i;});
//or or or
var a = "Sololearn",b=[],i;
for(i=a.length;i;b.push(a[--i]));
a=b;
//Sound like I answer how many way to do that instead of how to do that
+ 1
The attribute split is a excellent chioce to split a string. eg.
var a=‘javascript’
b=a.split(‘’)
c=b.join(‘’)
you can try