How to access a data from inside the object, being in the same object

Asked

Viewed 28 times

-3

let carryData = {
    prova: Number(34),
    semanal:Number(345),
    aExtra:Number(543),
    total:??? //quero o valor da prova, nesse mesmo objeto 
}

1 answer

1


If you want to declare ownership total with the same value, you will have to double the value assigned to prova.

Now if total is only a property to access the value, you can declare it as a getter.

let carryData = {
    prova: 34,
    semanal: 345,
    aExtra: 543,
    get total() {
        return this.prova;
    }
};

console.log(carryData.total);

Browser other questions tagged

You are not signed in. Login or sign up in order to post.