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

138
Vistas
Javascript Object Behavior Won't Assign Value

Trying to assign at anonymous object but the value became 'Array(0)'

I try to console the values below console.log(values, { state: state, values: values })

And got this result

[inpid: 'asd', inppwd: 'asd']
{state: 4, values: Array(0)}

Why the values in the object became Array(0)?

When i console.log(values, state) I got this result

[inpid: 'asd', inppwd: 'asd']
4

Here i implement the code

function getInputsValue() {
    let state = 4;
    let values = [];

    ... some code that make `values` became `[inpid: 'asd', inppwd: 'asd']`

    return { state: state, values: values }
}

any explaination? please

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

That's how Chrome displays a 0-length array in value summaries in the console. Empty arrays can still contain properties.

You are trying to add properties to an array, I recommend using plain objects instead. You can initialize the object like this:

let values = {
    inpId: '',
    inpPwd: ''
};

You can simply access the values by doing this.

values.inpId;
values.inpPwd;

This allows you to get and set the values within. The rest of the code doesnt need to be changed unless you iterate over the values array.

Side note

If you need the values object to be an array. You can simply change it to an array and add the objects into it.

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