Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

176
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda