0

I have an fire object obj. I JSON.stringify(obg)ed the object and it gives

{"12:23:34:45":{"Brand":"Sams","Carrier":"Car 1"},"23:34:45:56":{"Brand":"Sams","Carrier":"Car 2"}}

Beautified version is

{
"12:23:34:45":
    {
    "Brand":"Sams",
    "Carrier":"Car 1"
    },
"23:34:45:56":
    {"Brand":"Sams",
    "Carrier":"Car 2"
    }
}

What I have tried is to loop through this object to get the Carriers but it failed

for(let i in obj){
  console.log(i.Carrier);
}

I want to get the keys (12:23:34:45 and 23:34:45:56) from this object but not sure how to do this.

1 Answer 1

1

You do not need lopp here, just use Object.keys

var myObj = {"12:23:34:45":{"Brand":"Sams","Carrier":"Car 1"},"23:34:45:56":{"Brand":"Sams","Carrier":"Car 2"}};

console.log( Object.keys(myObj));

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks man a lot :), was struggling for a few hours. Thanks again!

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.