Convert an array to a string


I have this array

[12, 13, 22]

but I need to remove the brackets and spaces. You should print the following:

asked by Rafael Pereira 15.01.2018 в 01:43

3 answers


Using the toString () method could achieve this result, (response adapted to your comment code).

var array1= [100,200,300,400,500,600,700,800,900];
var array2=[1,2,5];
var posit ={
	return array1[el];

console.log(posit.toString()); // uso del método
answered by 15.01.2018 / 02:15

Explained the question, you can do it with map , as you said @DevJoel.

And, for a array I think it's better to use join than toString .

The method join() links all the elements of a Fix in a chain. The default separator is comma , , and it offers you the possibility of using another separator if necessary. Also, if an element is undefined or null is converted to an empty string.

For other separators, see examples in the documentation link.

Here I show a simplified form:

var act = [10002197,10001755,10001087,10001879,3508477478,10001881];
var posiciones = [0,2,3] // el debera imprimir (10002197,10001087,10001879)

var arrResultado = => act[i]);
answered by 15.01.2018 в 01:56

the best and fastest option is

array = [1,2,3,5]

will return the elements of the array in a string separated by a comma, if you want a different separation specified within the join " join(";") "

answered by 15.01.2018 в 11:41