Luke SpringWalker Luke SpringWalker - 1 month ago 6
JSON Question

Javascript - Append a string to keys of an object including a dot character

I have the following

javacript object
:

Object {description: "This is a description."}


which I'm sending to the backend using the angular's
$http.get
, but I need to append a string to the key before sending it using a
.


{bd.description: "This is a description."}


Is this possible?. So far I've been only able to create a
JSON
manually using the
.

It'd like to avoid creating a template of a
JSON
and filling it later, as the number of properties of the
JSON
is variable.

Thanks!

EDIT: it's not a nested object.

Answer

You could do something like this if you would like:

var myObject = { description: "this is stuff" } myObject['d.description'] = myObject.description delete myObject.description console.log(myObject) // { "d.description": "this is stuff" }

Comments