Reputation: 384
Here is the code :
var array = [];
$('.body-watch-logo').each(function () {
array[]['evendId'] = $(this).data('event');
array[]['timestamp'] = $(this).data('timestamp');
$now = new Date();
$outStr = now.getHours()+':'+now.getMinutes();
alert($outStr);
if(array[]['timestamp'] == $outStr) {
alert('Tring Tring Tring');
//do something here
}
$i++;
});
.body-watch-logo has several events in it with attributes eventId and startTime. So I want to store this information in array. Then compare the startTime which has only Hour and minute with current-time. If they are equal give an alert. Does anyone have an idea how to do this? Use Ajax may be. Please suggest.
Upvotes: 0
Views: 244
Reputation: 782775
You incremented i
, but never initialized it or used it as your array index. But you don't need to do either, since .each()
passes the index as an argument to the iteration function. See
http://api.jquery.com/jQuery.each/
The elements of the array are better implemented as objects, not sub-arrays.
var array = [];
$('.body-watch-logo').each(function (i) {
array[i] = { event: $(this).data('event'),
timestamp: $(this).data('timestamp')
};
$now = new Date();
$outStr = now.getHours()+':'+now.getMinutes();
alert($outStr);
if(array[i].timestamp == $outStr) {
alert('Tring Tring Tring');
//do something here
}
});
Upvotes: 1