javascript - Checking for two equal values in objects, in an array -
i have array objects in looks this:
i need check see if of start
dates same, , if are, objects. example, if arr[0], arr[3], arr[4] have start date of mon apr 25 2016 16:00:00 gmt-0700 (pacific daylight time), need select 3 objects , them.
i'm not sure how this, appreciated.
you can transform list of objects mapped start
attribute , check see if of dates contain more 1 object.
here's helper:
function transform(list) { var map = {}; (var = 0; < list.length; i++) { var object = list[i]; if (object.start in map) { map[object.start].push(object); } else { map[object.start] = []; map[object.start].push(object); } } return object; }
then need call transform
list of objects map of objects identified start dates. iterate through them , you'll of objects each start
date.
var startdates = transform(list); // list of objects mapped start date // loop through each start date (var startdate in startdates) { var listforstartdate = startdates[startdate]; // check see if more 1 object exists start date if (listforstartdate.length > 1) { // whatever want list of objects current start date } }
Comments
Post a Comment