Quantcast
Channel: Active questions tagged react-native+typescript - Stack Overflow
Viewing all articles
Browse latest Browse all 6287

Remove duplicates from an array of objects based on time created

$
0
0

I have an array of objects and there are some duplicate objects

const data = [{"id": "1011","name": "abc","Dob": "3/2/11","timeCreated": "16:03:41"},{"id": "1012","name": "xys","Dob": "6/5/12","timeCreated": "01:05:21"},{"id": "1011","name": "xyz","Dob": "3/2/11","timeCreated": "17:03:41"},{"id": "1011","name": "xyz","Dob": "3/2/11","timeCreated": "15:03:41"}]

I am removing duplicates in the array by using some()

let arr = [];data.forEach(obj => {  if (!arr .some(o => o.id === obj.id)) {    arr.push({ ...obj})  }});   

I need help filtering it and only keeping the latest object based off of "timeCreated"

so the data looks something like this:

{"id": "1012","name": "xys","Dob": "6/5/12","timeCreated": "01:05:21"},{"id": "1011","name": "xyz","Dob": "3/2/11","timeCreated": "17:03:41"},]

Viewing all articles
Browse latest Browse all 6287

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>