+ 1
What would be the right code when you want to sort the set method?
Based on this code, it says that the sort is not a function, it does not show the sorted newNum variable. Here's the code: let num = [3,6,-2,-5,7,3]; let newNum = new Set(num); newNum.sort(); console.log(newNum); Please correct me if it is wrong logic. Thank you.
3 Respostas
+ 7
Julius
The Set object does not have a sort method, but the Array object does, so you have to sort num array before you convert it to a set.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array
+ 3
You're welcome.
0
I see. Thanks, now it works