Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

142
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!