0

I have an object 'res' and it holds a field:

res.headers=new object();

im using this field as a map which holds key and value meaning:

res.headers['key']='value';

is there any way to get the content of this map by iterating it without knowing the key?

thank you!

1
  • Just a small note: nobody really uses the 'new object()' syntax, instead 'res.headers = {};' should be used for new objects and '[]' for new arrays. Commented Dec 15, 2011 at 4:08

2 Answers 2

2
for(var key in res.headers) {
    if(res.headers.hasOwnProperty(key)) {
        console.log(key + " -> " + res.headers[key]);
    }
}

or with Object.keys():

for(var key in Object.keys(res.headers)) {
    console.log(key + " -> " + res.headers[key]);
}
Sign up to request clarification or add additional context in comments.

Comments

1

Easiest thing to do is use a javascript library, like underscore for example, then use someting like:

arr = _.values(res.headers)
arr[0] // value of first element

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.