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

125
Views
Array give [object object] after pushing object inside

The array show as [object object] after I push the object inside it even though the object that are inside the array show up as what I want it to be . I tried searching google and YouTube but didn't find anything

let arr = []
let list = ""
let rev = {}
const btn = document.getElementById("savel")
btn.addEventListener("click", function() {
                 val1 = name.value
                 val2 = age.value
                shh ()                              
                console.log(val1)
})

function shh () {
     rev = {
                names: val1,
                ages: val2
}
showname.textContent = rev.names
showage.textContent = rev.ages
   arr.push(rev)
   console.log(arr)
   uul ()
}

function uul () {
                for (i=0; i<arr.length; i++) {
                                list = arr[i]
                }
                ul.innerHTML += `
                <li> ${list} </li>
                `
}
console.log(rev)
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

You're appending to the list array after the for loop ends. Change the uul function to:

function uul () {
    for (i=0; i<arr.length; i++) {
        list = arr[I];
        ul.innerHTML += '<li> ${list} </li>';
    }           `
}
about 4 years ago · Juan Pablo Isaza Report

0

You should use JSON.stringify().

If I have the following array and I try to show it in an alert

var myArray = [{name: "Jack"}, {name: "John"}];
alert(myArray);

The output will be [object Object],[object Object],

But if I use JSON.stringify:

alert(JSON.stringify(myArray))

the output will be [{"name":"Jack"},{"name":"John"}].

The same logic applies to your code and into the ul.innerHTML. Read more about here.

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!