Want to put output in a p tag and not in console.log

I want the data from my array to be output into the

element and be the actual value ,not “[object Object]”


That’s because you are trying to send an object (a complex) data structure to the screen. It doesn’t know how to handle it so it runs the toString method and that’s what that method returns for an object. You can break it apart and manually display the constituent parts. If you just want to see it, then you can do something like this:

document.getElementById("name").innerHTML = JSON.stringify(name, null, 2); 

That will convert it to a string so the screen knows what to do with it.

I am getting somewhere now. Thanks to you I tried:
document.getElementById(“name”).innerHTML = JSON.stringify(myArray);
and got back some real data (see below)

1 Like

If you want the actual value, you can just access that property, name.Age. But you’re going to have to tell it explicitly like that, you can’t just send the object or array and have the screen figure it out. Of course, you can wrap it in a function have have that do it.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.