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

378
Vistas
Is there a better way of writing variableName[0]?

Is there a better of writing const data = variableName[0]? I mean for variableName[0]. I do understand data is placed in index 0, but writing a number does not look professional ( to me atleast), So if there is some professional way someone knows, please share

To be more accurate, this is the case when the array has ONLY 1 element

almost 4 years ago · Santiago Trujillo
3 Respuestas
Responde la pregunta

0

You can try to use the array destructuring syntax:

const variableName = [1];
const data = variableName[0];
console.log(data);

const [data2] = variableName;
console.log(data2);

In above example it takes first array element and ignores the other ones. You can also destructure more than one element into named variables:

const [variable1, variable2] = yourArray;
almost 4 years ago · Santiago Trujillo Denunciar

0

The following is the shortest syntax in the modern JavaScript:

const [data] = variableName;
almost 4 years ago · Santiago Trujillo Denunciar

0

I would say that what looks potentially unprofessional is not so much writing a number, but rather storing data in an array like this. If your variable was an object {data: "someData"} instead of an array ["someData"] , then you could write

const {data} = variableName;

If you can't change the format, then there is nothing really wrong with variableName[0], but if you really want to avoid writing a number you could write

const [data] = variableName;

This may look a bit more cryptic to people not used to this syntax, though.

almost 4 years ago · Santiago Trujillo 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