Reputation: 11
I have the following var x = "bob"
and want to put var x value into "something"
var request = {
"id":"2",
"number":"12345",
"params":[{
"name":"bob",
"message":"hi"
}],
"something": "${x}"
}
I am new to JS and NodeJS and am stumped on how to easily do this.
Upvotes: 1
Views: 48
Reputation: 2165
you must use (dot) to change a javascript Object
var x = 'bob';
request.something = x;
Upvotes: 0
Reputation: 50291
Access the key using dot(.
) or square notation[]
var x = "bob"
var request = {
"id": "2",
"number": "12345",
"params": [{
"name": "bob",
"message": "hi"
}],
"something": "${x}"
}
request.something = x;
console.log(request)
Upvotes: 0