10

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.

Raghul Rajendran
  • 486
  • 2
  • 7
  • 25

3 Answers3

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

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