0
String to array
How to convert a string to an array in JavaScript ? let's say i got "Hello World" as a string (var str = "Hello World"); and I want to convert it to an array so I can use its letters as items with indexes and alert the whichever one I want. how can i do that? Any help would be appreciated. Thanks in advance. :)
6 Answers
+ 14
Use str.split() method
let str = "string i'm "
let newStr = str.split('');
console.log(newStr)
http://mdn.beonex.com/en/Core_JavaScript_1.5_Reference/Global_Objects/String/split
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/split
+ 3
to you here āāā
https://www.w3schools.com/jsref/jsref_tostring_array.asp
+ 2
Hi, a String is an array of characters ej:
var text = "Hola";
var word = text[2];
alert(word);
The exit is "l".
I hope I've helped.
PD: Sorry if i commeted a mistake but i learning english.
+ 1
@Lord Krishna thank you, that seems to be a helpful website
0
@Emmanuel thank you man, yes you've helped ,
no don't be sorry you're totally fine, we are all learning.
thank you again.
0
@James16 thank you man, although that wasn't what I was talking about but I did learn something from it.
Thank you.