dojo - JavaScript: Checking to see if an array of objects doesn't have a duplicate depending on a particular property? -
i have array of objects, objects can this:
{name: "object1", type: "event", props: {internalid: 1}} {name: "object2", type: "event", props: {internalid: 1}}
i want loop through array of these objects , want create new array of objects no duplicates (for me 2 items duplicates if have same internalid
in props
property)
i wondering best , efficient way "unique" objects original array , in new 1 based on internalid
property?
thanks
you accomplish pretty uniq method underscore or lo-dash. optimize things bit if array sorted. both libraries have documented code, @ approach problem.
here example:
var objs = [{ name: "object1", type: "event", props: { internalid: 1 } }, { name: "object2", type: "event", props: { internalid: 1 } }, { name: "object3", type: "event", props: { internalid: 2 } }]; var result = _.uniq(objs, false, function (item) { homecoming item.props.internalid; });
javascript dojo
No comments:
Post a Comment