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

257
Views
Why when I set the value of an hidden input to a value of an array of objects it makes every item in the hidden input array into [object Object]

I have this code:

for(let i =0; i < upbtn.length; i++){
  upbtn[i].addEventListener('click', function(){
    let whichTopic = i
    if(whichTopic == 0){
      return true
    }
    else{
      let arr = coursenewtopics.value
      arr = JSON.parse(arr)
      arraymove(arr, i, i-1)
      coursenewtopics.value = arr
      console.log(arr)
      console.log(coursenewtopics.value)
      //changeordertopicsform.submit()
    }
  })
}

I am trying to sort an array from an hidden input then set the value of the hidden input to the sorted array, I console logged the results from the sorted array(arr)

[
    {
        "type": "text",
        "name": "",
        "text": ""
    },
    {
        "type": "text",
        "name": "2",
        "text": ""
    },
    {
        "type": "text",
        "name": "1",
        "text": ""
    },
    {
        "type": "text",
        "name": "3",
        "text": ""
    },
    {
        "type": "text",
        "name": "4",
        "text": ""
    }
]

and the results are what I want, however when after I put this value I just logged of arr to the hidden input, then console log the value of the hidden input becomes:

[object Object],[object Object],[object Object],[object Object],[object Object]

why does JavaScript act this? how do I fix this an put the values into the hidden input without making them go [object Object]? I need them for a form later on.

Thanks!

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

so your problem is 'How to display an array of object literally'.

you can try JSON.stringify(arr, null, ' ')

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!