0

Hello i have an array of objects. Like this:

const obj = [{
   count: 10,
   value: count*2 // the previous count
}]

How can i reference 'count' on 'value' without having to find the index, or is a way to find the index of 'obj'?

Klod Lala
  • 143
  • 7

1 Answers1

3

You could take a getter with a reference to the same object.

const
    objects = [{
        count: 10,
        get value () { return this.count * 2; }
    }];

console.log(objects[0].value);
Nina Scholz
  • 351,820
  • 24
  • 303
  • 358