0

How can I add: "headers": { time: new Date().getTime() } to a Javscript object:

{
  "1": 3.7,
  "2": 0.5,
  "3": 1.0,
  "4": 60,
  "5": 180,
}

So the resulting object is (for example):

{
  "1": 3.7,
  "2": 0.5,
  "3": 1.0,
  "4": 60,
  "5": 180,
  "headers": { "time" : 1234 },
}

If I use push I get a “Uncaught SyntaxError: Unexpected token o” and I'm unsure of how to wrap the headers if I use object notation to add.

1 Answers1

0
var a = {
  "1": 3.7,
  "2": 0.5,
  "3": 1.0,
  "4": 60,
  "5": 180,
};

a.headers = { "time" : 1234 };
//OR
a["headers"] = { "time" : 1234 };
euvl
  • 4,716
  • 2
  • 25
  • 30