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

175
Vistas
Syntax error in an object which has an array of objects

I am wondering why the code below is invalid. It gives the following error: SyntaxError: missing ] in computed property name. If I remove the outer curly braces it works. But I am wondering why it wouldn't work with the curly braces.

const example2 = {[
  {
    'title': 'Hello World',
    'Author': 'John Doe',
  },
  {
    'title': 'Hello World2',
    'Author': 'John Doe',
  },
]};

console.log(example2);

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

0

Objects have key/value pairs. Your example2 object had an array (value) with no key.

const example2 = {"array" : [
  {
    'title': 'Hello World',
    'Author': 'John Doe'
  },
  {
    'title': 'Hello World2',
    'Author': 'John Doe'
  }
]};

console.log(example2);

about 4 years ago · Juan Pablo Isaza Denunciar

0

You're putting an array inside an object, without defining the key (or the property).

Object is a key/value pair, you can't give a value without a key.

var myObj = {
  myArr: [{
      'title': 'Hello World',
      'Author': 'John Doe',
    },
    {
      'title': 'Hello World2',
      'Author': 'John Doe',
    },
  ]
};
about 4 years ago · Juan Pablo Isaza Denunciar

0

You are getting this error:

SyntaxError: missing ] in computed property name

Because there is an error with the Object initializer syntax.

An object can be created using the “key: value” pair.

And in your case, you have initialized example2 object without the key.

const example2 = {
  "key": [{
      'title': 'Hello World',
      'Author': 'John Doe',
    },
    {
      'title': 'Hello World2',
      'Author': 'John Doe',
    },
  ]
};

console.log(example2);

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