You need to develop a function that takes an array of numbers and returns a new array containing only the unique numbers. What approach would you use to filter out the duplicates?
- Using a for loop and checking uniqueness manually
- Using Array.prototype.filter() and a custom filter function
- Using Array.from(new Set(array))
- Using Array.prototype.reduce() with a custom accumulator function
To filter out duplicate numbers in an array, you can use Array.from(new Set(array)). This creates a Set from the array (which only keeps unique values) and then converts it back to an array. It's a concise and efficient approach for this task.
Loading...
Related Quiz
- What does a 0 as the major version (e.g. 0.1.2) signify in semantic versioning?
- To parse URL-encoded data, Express uses the ______ middleware.
- How can you ensure the security of file uploads in a web application?
- How can you handle error events emitted by the request object in the http module?
- How does the placement of a package in dependencies or devDependencies affect the build process of a project?