1

I have the following object as you can see on console line 85. enter image description here

And I have the following JavaScript code

      for (var key in orderObject) {
        if (!orderObject.hasOwnProperty(key)) continue;
    
        var obj = orderObject[key];
        for (var prop in obj) {
            if (!obj.hasOwnProperty(prop)) 
              continue;
    
            console.log((prop + " = " + obj[prop]));
        }
      }

And you can see what this piece of code prints on the console on line 97.

What I want to achieve is first of all to access the keys, seller accepted the order , seller delivered the order etc. I can do for example Object.keys(orderObject) and it will print those keys. But I want to achieve so such manner that I get the key and the value for each item in that object. Ideally something like seller accepted the order, 1602709200 since I do not care about nanoseconds.

How can I achieve it?

I am mostly stuck because I treated it like an array an tried for(), forEach() but these cannot be used here.

1

2 Answers 2

2
for (const [key, value] of Object.entries(orderObject)) {
  console.log(`${key}: ${value.seconds}`);
}
Sign up to request clarification or add additional context in comments.

Comments

2

You can try this for get the keys and values

For(const [key, value] of Object.entries(orderObject)){
   console.log(key,value)
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.