I have a DataTable
which is being populated by JSON
. The days of the week (for example) are returning as a string
which i am applying .split(',')
to and is working in my forEach
function, but i need to apply a class to my days returned buttons but due to the space in the string it only falls into my 'Mon' button and not the rest due to the space.
Working code
var selectedDays = modifyRecordData.selectedDays;
var splitSelectedDays = selectedDays.split(',');
console.log(splitSelectedDays);
splitSelectedDays.forEach(day => {
if(day == 'Mon') {
alert('in Mon')
$('#mon').removeClass('btn-default');
$('#mon').addClass('btn-primary');
}
if (day == 'Tue') {
alert('in Tue')
$('#tue').removeClass('btn-default');
$('#tue').addClass('btn-primary');
}
// AND SO ON
})
This also returns
I have tried the following but none are working
var selectedDays = modifyRecordData.selectedDays;
var splitSelectedDays = selectedDays.split(',').trim();
and
var selectedDays = modifyRecordData.selectedDays;
var splitSelectedDays = selectedDays.split(',').trim();
var test = splitSelectedDays.trim();
also thruught about trying in the actual loop
as each one returned as a string
using the below
splitSelectedDays.forEach(day => {
splitSelectedDays.trim();
But always get the function error.
I am wanting to remove the space, then lowercase the value then i can use the var
in on addClass
function rather than an IF
for each day of the week