My journey began with a quick peek at this particular inquiry. However, the approach discussed there utilized custom typing. I am currently iterating over object entries using a for-of loop. Here's a snippet of the values I'm dealing with below. During this process, I discovered that in order to access functions on a certain type of object, checking the instance is necessary. This logic applies to everything except strings. It seems like I have to utilize String
instead of string
when applying the instanceof
operator, yet this leads to errors due to the fact that String
is not compatible with string
. As a result, I find myself pondering upon alternative solutions and wondering if there exists a more efficient way to tackle this issue.
const value =
{
EnableDataMining: 1, EnableReassembly: 0, Alarm: [1,2,3],
AllowQuery: 1, AllowDrilldown: 1, MessageType: ["sms", "msm","carrier pidgeon"],
AllowBypass: 0, Bybass: (1) [false, "01/01/1970"]
}
for(const [k, v] of Object.entries(value))
{
th.headers = td.headers = th.textContent = key;
if(v instanceof Array) v.map(i => td.textContent = i);
if(v instanceof Number) td.textContent = v.toString();
if(v instanceof String) td.textContent = v;
console.log(k, v);
}