96.8k views
3 votes
How to create json object from variables javascript

1 Answer

4 votes
Not entirely sure what you want to achieve, but consider this program:

var a = 'foo';
var b = 'bar';

var c = { first : a, second : b };

console.log(JSON.stringify(c, null, 4));

A json object c is constructed using the values from variables a and b. Is this what you mean?
User Tschuege
by
8.0k points