Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

“new Set” is returning an empty set in nodejs

Instead of:
const set = new Set(['foo', 'bar', 'baz', 'foo']); // Set(3) { 'foo', 'bar', 'baz' }
const result = [...set] // []

Do:
const set = new Set(['foo', 'bar', 'baz', 'foo']); // Set(3) { 'foo', 'bar', 'baz' }
const result = Array.from(set) // ['foo', 'bar', 'baz']
 
PREVIOUS NEXT
Tagged: #returning #empty #set #nodejs
ADD COMMENT
Topic
Name
7+4 =