Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to convert Set to string with space?

I want to convert JavaScript Set to string with space.

For example, if I have a set like:

var foo = new Set();
foo.add('hello');
foo.add('world');
foo.add('JavaScript');

And I'd like to print the string from the set: hello world JavaScript (space between each element).

I tried below codes but they are not working:

foo.toString(); // Not working
String(foo); // Not working

Is there simplest and easiest way to convert from Set to string?

like image 221
KimchiMan Avatar asked Nov 11 '17 21:11

KimchiMan


People also ask

How do I convert a set to a string in Salesforce?

Converting Set into StringString setString = string. valueof(setdata). replace('{', ”).

How do you turn a string into an array in Javascript?

The split() method splits a string into an array of substrings. The split() method returns the new array. The split() method does not change the original string. If (" ") is used as separator, the string is split between words.


1 Answers

You can use Array.from:

Array.from(foo).join(' ')

or the spread syntax:

[...foo].join(' ')
like image 190
Mihai Alexandru-Ionut Avatar answered Oct 08 '22 10:10

Mihai Alexandru-Ionut