Remove duplicate records from observable

I am having duplicate records in my observable, How do I remove only the duplicate records,
I am having an API that retrieves data from a server and I have pull to load method as well as infinite scrolling the thing is if data retrieved from a server is not a new data it adds into the observable as duplicates, now I need to know how to avoid and here is a sample code:

for (var i=0; i<items.length; i++) {
else {
feed.insertAt(i, items[i]);

So if anyone can help, I’d highly appreciate it.

When adding new items, you could check if the item already exists first.

if (!feed.contains(items[i])){

if you need to update existing items, you can use the replaceAt function:

I hope this points you in the right direction.