简体   繁体   中英

javascript json object with objects inside

I have a JavaScript code.

var a = {'a': 5};
var b = {'b': 6};
var c = {a, b}; // produces an error

How can I create such object, so that I can refer to it like ca and it gives me required data?

I think you are trying to do this:

var a = {'a': 5};
var b = {'b': 6};
var c = {'a':a, 'b':b}; 
console.log(c.a)
var a = {'a': 5};
var b = {'b': 6};
var c = {a, b};

c.a = a;
c.a.a === 5; // true

c = {
  a: {'a': 5},
  b: 6
};
c.a.a === 5; // true

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM