Possible Duplicate:
best way to get the key of a key/value javascript object
foo = {bar: “baz”}
How do you get a listing of all the properties and values within foo?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
A
for inloop can give you the key and value. Remember to useconst,letorvarfor variable declaration in strict mode.From the console:
If the object you’re looping over has has inherited properties from its prototype, you can prevent the inherited properties from being looped over using the
Object.hasOwnProperty()function like this: