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

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

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