Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove duplicate String(Ignore Case) from list in angular 8 using lodash

I have a list of String with duplicate entries , So i want to remove them irrespective of Case

let duplicates = ['Hello', 'Hi', 'hello'];
let uniques = _.methodName(duplicates);

// output should be
['hello','Hi'] OR ['Hello','Hi']
like image 646
Ankesh Pandey Avatar asked Jan 20 '26 09:01

Ankesh Pandey


1 Answers

You can use _.uniqWith() with a callback as following:

let duplicates = ['Hello', 'Hi', 'hello'];

let uniques = _.uniqWith(duplicates, (a,b) => a.toLowerCase() === b.toLowerCase())

console.log(uniques);
<script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.15/lodash.min.js"></script>
like image 122
Harun Yilmaz Avatar answered Jan 22 '26 22:01

Harun Yilmaz



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!