มี 3 วิธี: 1) string.split() 2) Spread operator (...) ES6 3) Array.from() ES6
1. string.split()
string.split('');
ตัวอย่าง
<html> <body> <script>
const str = 'Tutorialspoint';
var d = split('');
document.write(d);
</script> </body> </html>
ผลลัพธ์
T,u,t,o,r,i,a,l,s,p,o,i,n,t
2. Spread Operator
[...string];
ตัวอย่าง
<html> <body> <script>
const str = 'Tutorix';
var d = [...str];
document.write(d);
</script> </body> </html>
ผลลัพธ์
T,u,t,o,r,i,x
3. Array.from()
Array.from(str);
ตัวอย่าง
<html> <body> <script>
const str = 'Tutorix and Tutorialspoint';
var d = Array.from(str);
document.write(d);
</script> </body> </html>
ผลลัพธ์
T,u,t,o,r,i,x, ,a,n,d, ,T,u,t,o,r,i,a,l,s,p,o,i,n,t