Why is it necessary to use the spread operator with a set why can't I log it to the console without using the spread operator?
This wouldn't work, what is going on to make this not work?:
function duplicateSet(str) {
const arr = str.split(" ");
const set = new Set(arr);
const newString = set.join(" ");
return newString;
}
console.log(duplicateSet("This is is a test test string"));
This works but why?:
function duplicateSet(str) {
const arr = str.split(" ");
const set = new Set(arr);
const newString = [...set].join(" ");
return newString;
}
console.log(duplicateSet("This is is a test test string"));