I currently have a page that contains an unordered list. That list is initially populated by querying my db, with each list item having a time stamp and text. Using javascript and AJAX, this page updates the unordered list dynamically every 10 seconds, if new data has come in.
What is the easiest and most efficient way to remove list items from this unordered list if the items are older than 24 hours?
My inclination is to do the following:
- In the js file, load all list items in the unordered list into an array
- During the js call to get data, if data comes back, add those items to the array as well
- Every time the getData() function is called, also call a removeData() function that removes all items that are older than 24 hours.
Also, I have had issues trying to figure out the correct way to add list items to a javascript array. Here is the code that I have been trying for adding all list items to an array:
var list = new Array();
$(".listname").each(function (i){
list.push($(this));
});
to remove list items from the array, I expect to use:
list.pop();