Dylan Lott
Dylan Lott

Reputation: 421

getting [object Object] out of my data arrays

JSBin Link

When I run the code in the jsBin, I get the following object churned out:

  Game Modding: [[object Object] {
  event_type: "program",
  icon: "game-modding",
  title: "Game Modding",
  type: "info"
}, [object Object] {
  event_type: "program",
  icon: "game-modding",
  title: "Game Modding",
  type: "info"
}, [object Object] {
  event_type: "program",
  icon: "game-modding"
  title: "Game Modding",
  type: "info"
}]

I need to get the [object Object] out of there, but after an hour of Google searching I'm not seeing anything that is telling me why it's showing up like this.

I'm using underscore to render and filter the data, and so far it's come together pretty quickly but this object Object thing is getting in the way of actually using my data. The whole point of this is that I'm trying to group events I'm given by their name and show the times that every event is offered and a single description of the event.

Any help is extremely appreciated!

Upvotes: 1

Views: 92

Answers (2)

Josh Beam
Josh Beam

Reputation: 19792

JSBin is coercing the object to a string in order to print it in their console.

If you open up your dev tools console in your browser, you'll see that it's working as expected (you hit CMD+opt+j to open up Chrome dev tools on Mac, for example):

output

Just as an aside, whenever you try to "print" an object to the screen, the browser will call the object's .toString method:

var myObj = {};

someDOMElement.innerHTML = myObj;

// => on the screen, you'll see [object Object]

Upvotes: 2

Aurélien Thieriot
Aurélien Thieriot

Reputation: 5923

This is most likely a weird choice from the JSBin side of things.

If you try your code in the Chrome Console (for example), you will be able to see your list in perfect order.

Other people have reported similar issues:

https://github.com/jsbin/jsbin/issues/2310

Upvotes: 3

Related Questions