OneBite.Dev - Coding blog in a bite size

convert an array to a string in Javascript

Code snippet on how to convert an array to a string in Javascript

let arr = [1,2,3];
let s = arr.join("");

This code uses the join() method to convert an array, arr, into a string, s. The join() method takes an argument, which in this case is an empty string. By passing an empty string into the join() method, the elements of the array arr will be connected together with no space between them. The resulting string s will contain the values of the array arr in sequence, without any space in between. For example, if arr = [1,2,3] then s = "123".

javascript