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

281
Vistas
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 Respuestas
Responde la pregunta

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