After following the reference link, I successfully implemented sorting and column functionality. However, there are two remaining tasks that I require assistance with.
Firstly, I need to customize the names of the columns according to my preference (e.g., changing 'date' to 'Date' and 'bus_name' to 'busName').
Secondly, I want to eliminate filtered arrays. Although I found a solution that worked, it also removed empty strings at the end of the array. My goal is to remove any empty strings or undefined values from the array without impacting the original mapped array.
This was the initial accepted answer provided:
var array = [{ date: " ", bus_name: 'Thomas #1', driver_name: 'Sam', time_start: '9AM', time_end: '5PM' }, { date: '2012-02-11', bus_name: 'Thomas #2', driver_name: 'Samantha', time_start: '8AM', time_end: '4PM' }, { date: '2011-02-02', bus_name: 'Thomas #3', driver_name: 'Peter', time_start: '12PM', time_end: '7PM' }, { date: '2010-06-04', bus_name: 'Thomas #4', driver_name: 'Eddie', time_start: '11AM', time_end: '6PM' }, { date: " ", bus_name: 'Thomas #5', driver_name: 'Raul', time_start: '4AM', time_end: '1PM' }, { date: '2014-04-03', bus_name: 'Thomas #6', driver_name: 'Jessie', time_start: '5AM', time_end: '2PM' }], result = array .filter(o => o.date !== ' ') .map(({ date, bus_name }) => ({ date, bus_name })) .sort((a, b) => a.date.localeCompare(b.date));
console.log(result);
In regards to filtering, I aim to exclude ' ', 0, or undefined values from the mapped array. I am looking for guidance on incorporating this modification while maintaining the structure established by the accepted answer mentioned earlier. The array in question is stored in localStorage.
Please refer to the guidelines specified in the linked resource below!
Access the reference here: Filtering undefined or empty strings from array of objects in Javascript