To use the unique function from the underscore library in JavaScript, first make sure you have installed underscore.js. Then, you can call the unique function by passing an array as a parameter:
index.tsx146 chars7 lines
In the above example, we first require the underscore library using var _ = require('underscore');
. Then, we define an array arr
with duplicate values. Finally, we use the _.uniq()
function to get an array with unique values and store the result in uniqueArr
.
Note that _.uniq()
function does not modify the original array, but returns a new array with unique values.
gistlibby LogSnag