Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

174
Views
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 answers
Answer question

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 Report

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 Report

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!