I am having trouble referring to any variables with "-" in the variable name. I feel the answer is something very simple but I can't figure it out.
For Example
var headers = {
"content-type": "application/json;charset=UTF-8",
"content-length": "261",
"connection": "close",
"date": "Fri, 01 Apr 2022 09:12:56 GMT",
"server": "nginx",
"vary": "Accept-Encoding",
"x-mbx-uuid": "88911a02-ff75-4cc0-b8ef-1ea4ab0edabd",
"x-mbx-used-weight": "10",
"x-mbx-used-weight-1m": "10"
}
to refer to an element, the following works
console.log(headers.server)
But the following doesnt work because javascript doesn't recognise - . How do I refer to x-mbx-used-weight-1m in this case?
console.log(headers.x-mbx-used-weight-1m)
You need to use square brackets and quote marks:
headers["x-mbx-used-weight-1m"]