Curious what I’m doing wrong here :
employee_ids = $('[data-employee_id="'+employee+'"]');
timestamp_ids = $('[data-scheduled_on="'+timestamp+'"]');
var common = $.grep(timestamp_ids, function(element) {
$.each(employee_ids, function(idx, item) {
if ( item === element ) { console.log ("omg!") };
});
});
This returns just the list of timestamp_ids and not that array compared against employee_ids looking for a single match.
You are not using .grep correctly. Each iteration of grep should return a boolean: true to add it to the result array, false to ignore it.
Note that IE does not support
.indexOfon Arrays, you will have to implement the comparison some other way.EDIT: if you are trying to find a single item of an array that matches some criteria, i would suggest just using a regular for loop: