I can’t get the contents of an object to display in the console.log correctly on different browsers.
Here is the script in question:
[code]
function test1b() { // new way
var arr = [
{“name”:”apple”, “count”: 2},
{“name”:”orange”, “count”: 5},
{“name”:”pear”, “count”: 3},
{“name”:”orange”, “count”: 16},
];
var newArr = arr.filter(function(item){
return item.name === “orange”;
} );
// console.log(“Filter results:”,newArr);
console.log(“Filter results:”,newArr.toSource()); // OK for FF
// console.log(“Filter results:”,newArr.toString());
}
test1b();
If you run it in Firefox it displays correctly with the .toSource() method
but it displays <unavailable> or [object Object],[object Object] for the Chrome browser.
If you use .toString() instead, it does not display the object contents correctly in either browser
Similar results if you leave off the .toString() or .toSource altogether.
The different statements are (un-)commented in the last 3 lines of the ‘test1b’ function
Why can I display the object contents correctly in the console.log
ONLY in FF with the .toSource() method? Is there some special setting
for the console.log output that need to be set to see the contents correctly?
Why does the console.log display either <unavailable> or [object Object] and not the contents?