Trying to retrieve a specific value by providing the literal key in a JavaScript object. The image below indicates that "filter" is equal to "Approved", sourced from reimb_status_description.
Line 6 of code assigns filter to the value.
const filter = Object.values(jsonData[i]["reimb_status_description"]).join("");
I am confused because without .join("")
, filter would be "A,p,p,r,o,v,e,d" as an array of letters. Can someone explain why it becomes an array instead of just a string? Also, is there a more efficient way to extract the desired data?
https://i.sstatic.net/s5S3N.png
function PopulateReimbursementTable(jsonData, appliedFilter)
{
ClearReimbursementTable();
for(var i = 0; i < jsonData.length; i++)
{
const tr = document.createElement("tr");
const entries = Object.entries(jsonData[i])
const filter = Object.values(jsonData[i]["reimb_status_description"]).join("");
console.log("filter: " + filter)
for(const [key, property] of entries)
{
if(fields.includes(key)){
console.log(key + "\t" + property);
const td = document.createElement("td");
if(key == "reimb_date_submitted" || key == "reimb_date_resolved"){
if(property == null)
{
td.innerHTML = "tbd";
}else{
var d = new Date(property);
let formatted_date = appendLeadingZeroes((d.getMonth() + 1)) + "-" + appendLeadingZeroes(d.getDate()) + "-" + d.getFullYear();
//console.log(formatted_date)
td.innerHTML = formatted_date;
}
} else if(key == 'reimb_amount'){
if(property === null || property === undefined)
{
td.innerHTML = "tbd";
}else{
td.innerHTML = formatter.format(property);
}
}
else
{
if(property === null || property === undefined)
{
td.innerHTML = "tbd";
}else{
td.innerHTML = property;
}
}
if(fields.includes(key))
{
tr.appendChild(td);
}
}
}
if(appliedFilter == "All"){
reimbTableBody.appendChild(tr);
}
else if(filter == appliedFilter){
reimbTableBody.appendChild(tr);
}
}
}