Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
118
rated 0 times [  120] [ 2]  / answers: 1 / hits: 22806  / 14 Years ago, tue, december 28, 2010, 12:00:00

Now as example, I'm getting an response which has partially the key/values as an javascript object:



status: '200 OK',
'content-encoding': 'gzip'


I can easily read out and log the status message by: headers.status but when I try to log the content-encoding (which I need in this particular situation) it errors on:



headers.'content-encoding' <- obviously the quotes it doesn't like
headers.content-encoding <- obviously the '-' it doesn't like


How am I suppose to get/read/log it's content-encoding value?



Greets,



m0rph3v5


More From » json

 Answers
6

Javascript also supports square bracket notation for referring to properties so if headers is an appropriate object, you can use headers['content-encoding'].


[#94465] Sunday, December 26, 2010, 14 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
willieelisham

Total Points: 201
Total Questions: 108
Total Answers: 106

Location: Zambia
Member since Sat, Oct 31, 2020
4 Years ago
;