Convert a list `[1, 2, 3]` to a string '{1, 2, 3}' in Javascript -


i need convert lists [1, 3, 2] or [1,3] or [1,4,5] strings of form '{1, 3, 2}', '{1, 3}' '{1, 4, 5}'.

i can think of couple of ways this, not elegant one. wondering how solve this. there elegant solution possible?

you can this.

var result = '{'+ input[0];  for(var index = 1; index < input.length; index++) {    result = result + ' '+ input[index]; } result = result + '}'; 

or

var result = '{' + input.join(', ')+ '}'; 

remember give space after ','.


Comments

Popular posts from this blog

mysql - Dreamhost PyCharm Django Python 3 Launching a Site -

java - Sending SMS with SMSLib and Web Services -

java - How to resolve The method toString() in the type Object is not applicable for the arguments (InputStream) -