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

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

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 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