Hi guys, It's me again. I'm checking if objects containg value with Object.keys like below: Object.keys(obj).length Code (markup): It would return the list like this: 0 0 0 3 0 0 Code (markup): The list is unordered and number of items is variable depending on an amount of objects being checked. It would generated automatically. So how do I pick the only one that has data and ignore the rest. I do the switch and it isn't working. var flag; switch (Object.keys(obj).length) { case 3: flag = true; break; // => it does not break case 0: flag = false; break; default: flag = false; } console.log(flag); // still => false, false, false, true, false, false Code (markup): Doing this doeesn't work either: var flag; if(obj !== 'undefined') { flag = true; } else { flag = false; } console.log(flag); // false, false, true, false, false, false Code (markup): Thank you,
What on earth are you feeding that for values that returns multiple keys that equals zero? I'm not following what it is you're trying to do here whatsoever. Doesn't make a lick of sense.... what's the "list" / data being processed?!? What about it do you actually want to know? What are you doing where the number of keys is something you want to know?
Thank for response. As far as I researched, it has to write a counter to count an object with data only. So how to count it? Here's what the law data look like: {} {} {} { name: 'John', surname: 'Doe' } {} {} Code (markup):
What I'm not getting is why you even have empty objects, and how those objects are stored. Are they in an array? The solution to my mind is to fix the data source so it's not vomiting up empty records, or purging the data of empty records since NONE of them should be serving a legitimate purpose. Also, what do you mean by "it"? As in "It has to write"... what has to write? FROM what?