M
M
MortSith2021-06-12 14:58:29
JavaScript
MortSith, 2021-06-12 14:58:29

Is it possible to take the value of a neighboring key inside an object?

this is exactly what I want, how to do it right?

let left = "hi ",
    right = "!!!!?";

let mass = [
  {
    name: "Kianu",      //взять значение отсюда
    age: 232,
    message: [left + this.name + right]  //вставить это значение между left и right, 
  },
  
   {
    name: "Saruman",
    age: 19332,
    message: [left + mass[1].name + right]
  },
];

console.log(mass[0].message)

Answer the question

In order to leave comments, you need to log in

2 answer(s)
0
0xD34F, 2021-06-12
@MortSith

https://developer.mozilla.org/en/docs/Web/JavaScript...

A
Alexey, 2021-06-12
@AleksRap

It is impossible, because at the time of accessing the property of the object, the object itself has not yet been created

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question