Skip to content

Commit ecf6030

Browse files
authored
Get unique values in an array
1 parent 7810899 commit ecf6030

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

README.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,3 +135,26 @@ myArray.flat(2) // [2, 3, 4, 5 ,7,7, 8, 9, [1, 1]]
135135
myArray.flat(infinity) // [2, 3, 4, 5 ,7,7, 8, 9, 1, 1];
136136
137137
```
138+
139+
#Get unique values in an array
140+
141+
```javascript
142+
const numbers = [1,1,3,2,5,3,4,7,7,7,8];
143+
144+
//Ex1
145+
const unieqNumbers = numbers.filter((v,i,a) => a.indexOf(v )=== i )
146+
console.log(unieqNumbers) //[1,3,2,5,4,7,8]
147+
148+
//Ex2
149+
const unieqNumbers2 = Array.from(new Set(numbers))
150+
console.log(unieqNumbers2) //[1,3,2,5,4,7,8]
151+
152+
//Ex3
153+
const unieqNumbers3 = [...new Set(numbers)]
154+
console.log(unieqNumbers3) //[1,3,2,5,4,7,8]
155+
156+
//EX4 lodash
157+
const unieqNumbers4 = _.uniq(numbers)
158+
console.log(unieqNumbers4) //[1,3,2,5,4,7,8]
159+
160+
```

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy