+ 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?

12th Oct 2017, 11:33 AM
koala 🐹
koala 🐹 - avatar
2 Answers
+ 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
12th Oct 2017, 12:01 PM
Yanothai Chaitawat
Yanothai Chaitawat - avatar
+ 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
12th Oct 2017, 12:06 PM
lee