How to store parts of a javascript object into variables?

I am new to javascript and I have the following object:

Stats: {
 "life": {
  "progress": 18,
  "counter": 1
 },
 "anxiety": {
  "progress": 24.5,
  "counter": 2
 },
 "mood": {
  "progress": null,
  "counter": 0
 },
 "cognition": {
  "progress": null,
  "counter": 0
 }
}

I’m needing to check if the counter for anxiety, mood, and cognition are > 0, and if they are I must return True. How can I iterate over this object and check for these specific parts of the object?
Expected output for this would be

false

If I am to update the object:

Stats: {
 "life": {
  "progress": 18,
  "counter": 1
 },
 "anxiety": {
  "progress": 24.5,
  "counter": 2
 },
 "mood": {
  "progress": null,
  "counter": 1
 },
 "cognition": {
  "progress": null,
  "counter": 1
 }
}

I want to return

True

Thank you.

Answer

You can store the properties to check in an array, use Object.keys to filter out the properties that aren’t included in the array, then use Array.every to check whether each object’s counter property is greater than 0.

const keysToCheck = ["anxiety", "mood", "cognition"]

function validate(obj){
  return Object.keys(obj).filter(key => keysToCheck.includes(key)).every(key => obj[key].counter > 0);
}

console.log(validate({
 "life": {
  "progress": 18,
  "counter": 1
 },
 "anxiety": {
  "progress": 24.5,
  "counter": 2
 },
 "mood": {
  "progress": null,
  "counter": 0
 },
 "cognition": {
  "progress": null,
  "counter": 0
 }
}))