0

I am having the following JavaScript object:

var Fruit = { Apple:{ Color: "Red" }, Banana:{ Color: "Yellow" }, Lemon:{ Color: "Yellow" } }

How can I refer Fruit.Lemon.Color to Fruit.Banana.Color ?

I've tried this

Lemon:{ Color: Fruit.Banana.Color }

but not work...

Lastly, I use the following method:

var Fruit = { Apple:{ Color: "Red" }, Banana:{ Color: "Yellow" } } Fruit.Lemon = { Color: Fruit.Banana.Color }

It works fine, but I want to keep all objects inside one scope of codes, no extra lines.

kitlee
  • 110
  • 8

0 Answers0