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

279
Views
Keys in object include characters that aren't allowed in identifiers

In my code I have this variable:

const operatorPrice = this.state.operatorPrice;

The value of operatorPrice is an object that looks like such:

enter image description here

Now, I want to put those into two separate Tables like such:

4/28/2022

    name       price   category
    product1    $20      oil

5/28/2022

    name       price   category
   product1    $20      oil

However I am getting this error: error

I guess I understand that the value of this.state.operatorPrice is not an array but I don't know in this format how to access the data and break it up. Any help or documentation would be awesome.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

The keys in this object here include characters that aren't valid in normal identifiers. You can't for example access it like this:

operatorPrice.4/28/2022

That's clearly not valid! JavaScript would interpret that key as division with numbers.

Instead you have to use bracket notation to access it:

operatorPrice["4/28/2022"]

Note that unlike using dot notation, any expression can be used within the brackets, so this also does the same as above:

operatorPrice[["4", "28", "2022"].join("/")]
// or even just
operatorPrice[[4, 28, 2022].join("/")]

As @JeffMercado suggests, you should use Object.keys or Object.entries to get the keys (and corresponding entries if required).

const keys = Object.keys(operatorPrice);

keys.forEach((key) => {
    operatorPrice[key]; // bracket notation again!
});
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!