Removes Duplicate JSON Elements for a Value of a Certain Key
This sample removes duplicate JSON elements for a value of a certain key. When the value of the certain key is removed, only a first duplicate element is left. Also I had wanted to be used for Google Apps Script. So it became like this.
Script :
function removeDup(arr, key){
var temp = [];
var out = [];
arr.forEach( function (e, i) {
temp[i] = (temp.indexOf(e[key]) === -1) ? e[key] : false;
if (temp[i]) out.push(e);
});
return out;
}
JSON :