I am trying to display the keys and values of an object but I'm getting only an error saying:
0[object Object]1[object Object]2[object Object]3[object Object]
What am I doing wrong?
My object, according to console.log is:
(4) [{…}, {…}, {…}, {…}]
0
:
{text: "Now", time: "Now"}
1
:
{text: "09:00", time: "09:00"}
2
:
{text: "09:30", time: "09:30"}
3
:
{text: "10:00", time: "10:00"}
length
:
4
__proto__
:
Array(0)
I am trying t display it with:
var html='';
$.each( data.times, function( key, val ) {
html+=key+val;
});
createElement("times", html );
0[object Object]is an "error"?data.timesis an array of objects.keywill be the index of the current element (0, 1, 2, ...) andvalis the element (an object) at that index. Calling.toString()on one of these objects returns[object Object]->0[object Object]