{"id":861,"date":"2017-05-17T13:01:10","date_gmt":"2017-05-17T07:31:10","guid":{"rendered":"https:\/\/blog.binarybits.net\/?p=861"},"modified":"2017-05-17T13:21:02","modified_gmt":"2017-05-17T07:51:02","slug":"remove-duplicate-list-items-from-sharepoint-rest-call-result-using-javascript","status":"publish","type":"post","link":"https:\/\/blog.binarybits.net\/remove-duplicate-list-items-from-sharepoint-rest-call-result-using-javascript\/","title":{"rendered":"Remove duplicate list items from SharePoint REST call result using JavaScript"},"content":{"rendered":"
The following code snippet show how to remove duplicate list items in the JSON result of a SharePoint REST call using JavaScript.<\/p>\n
Function Definition:<\/strong><\/p>\n Function Usage:<\/strong> <\/p>\n","protected":false},"excerpt":{"rendered":" The following code snippet show how to remove duplicate list items in the JSON result of a SharePoint REST call using JavaScript. Function Definition: function RemoveDuplicateItems(items, propertyName) { var result = []; if (items.length > 0) { $.each(items, function (index, item) { if ($.inArray(item[propertyName], result) == -1) { result.push(item); } }); } return result; } […]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"inline_featured_image":false,"footnotes":""},"categories":[251,62],"tags":[250,243,208],"yoast_head":"\nfunction RemoveDuplicateItems(items, propertyName) {\r\n var result = [];\r\n if (items.length > 0) {\r\n $.each(items, function (index, item) {\r\n if ($.inArray(item[propertyName], result) == -1) {\r\n result.push(item);\r\n }\r\n });\r\n }\r\n return result;\r\n}<\/pre>\n
\nIn the below code, assumption is that, the REST call returns data.d.results<\/em> and the column for which duplicate items need to be removed is Title<\/em><\/p>\nvar items = data.d.results;\r\nitems = RemoveDuplicateItems(items, 'Title');<\/pre>\n