I currently have a page containing an unordered list. This list is initially populated with a query from my db, with each list item having a timestamp and text. Using javascript and AJAX, this page updates the unordered list dynamically every 10 seconds if new data is entered.
What is the easiest and most effective way to remove list items from this unordered list if items are older than 24 hours?
My tendency is this:
- In js file load all list items into unordered list into array
- During js call to get data, if data is returned, add these elements to the array as well
- Each time the getData () function is called, also call the removeData () function, which removes all elements older than 24 hours.
Also, I was having trouble finding the right way to add list items to a javascript array. Here is the code I'm trying to add all the elements of a list to an array:
var list = new Array();
$(".listname").each(function (i){
list.push($(this));
});
to remove list items from an array, I expect to use:
list.pop();
source
share