In JavaScript and Jquery how to convert the string to array and same array convert to string and check them using typeof method in JavaScript.
Asked
Active
Viewed 3.3k times
10
-
add source `string` and `array` – Tushar Aug 18 '15 at 08:52
-
you can make use of array.join(key) to make array to string and you can make use of string.split(key) you can take a look at those functions – Oli Soproni B. Aug 18 '15 at 08:53
-
What is this an array *of*? – user2864740 Aug 18 '15 at 08:55
-
You can create JSON object (which is an array, usually consisting of arrays, then stringify it if you want string – pokrak94 Aug 18 '15 at 08:52
-
Does this answer your question? [How can I get a character array from a string?](https://stackoverflow.com/questions/4547609/how-can-i-get-a-character-array-from-a-string) – Heretic Monkey Jul 03 '23 at 18:43
3 Answers
19
var arr = "abcdef".split(''); // creates an array from a string
var str = arr.join(''); // creates a string from that above array

Jaromanda X
- 53,868
- 5
- 73
- 87
5
From String to Array you can Use split()
Method
var str = "How are you doing today?";
var res = str.split(" ");
console.log(res); // How,are,you,doing,today? it will print
From Array to String you can use Join()
method or toString()
Method

stackover flow
- 81
- 6
1
If you want do it manually, without any JavaScript methods. Try the below
String to Array
var str = "STRING";
var arr = [];
for(int i=0; i<=str.length; i++)
arr[i] = str.charAt(i);
Array to String
var str = "";
var arr = ["S","T","R","I","G"];
for(int i=0; i<=arr.length; i++)
str +=arr.charAt(i);

RevanthKrishnaKumar V.
- 1,855
- 1
- 21
- 34