I was studying up on the .filter() method in Javascript. I came across this example online.
var heroes = [
{name: "Batman", franchise: "DC"},
{name: "Ironman", franchise: "Marvel"},
{name: "Thor", franchise: "Marvel"},
{name: "Superman", franchise: "DC"}
];
var marvelHeroes = heroes.filter(function(hero) {
return hero.franchise == "Marvel";
})
document.write(marvelHeroes);
I expect to get an array of objects showing only the Marvel heroes. However, when I try to print the results of the marvelHeroes variable, I am getting the following result:
[object Object],[object Object]
Can someone tell me what is wrong here?
console.log(marvelHeroes)ordocument.body.innerText = JSON.stringify(marvelHeroes);Closing this.document.write(JSON.stringify(marvelHeroes));and check the output.