Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

101
Vistas
How do you add a predefined const as a object property

I don't know if its even possible but I'm wondering if you can add a const as an object property for an object.

So for example something like this:

const x = "age";

let array = {
name : "Tom",
x: "15";
}

So, in my case adding a new property to the object called 'age'. Where x is the variable that was already defined.

This is probs a dumb question but thanks in advance :)

about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

try this code :

const x = "age";

let array = {
name : "Tom",
[x]: "15";
}
about 4 years ago · Juan Pablo Isaza Denunciar

0

You can use a computed property name

const key = "age";
const value = 15;

let object = {
  name : "Tom",
  [key]: value
}

console.log(object);

But you can also take advantage of the shorthand notation by declaring a property that will take the name of the variable passed as well as assign its value to the property.

const age = 15;

let object = {
  name : "Tom",
  age
}

console.log(object);

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda