console.log(object);
另一個是寫個 dump 函數
function dump(obj) {
var out = '';
for (var i in obj) {
if (typeof obj[i] === "object")
out += i + ": {\n" + dump(obj[i]) + "}\n";
else
out += i + ": " + obj[i] + "\n";
}
return out;
}
Example:
<script>
var book = {
name: 'Javascript tutorial',
price: 50,
index: {
1: 'introduction',
2: 'hello world'
},
toString: function () { return "name: " + this.name + ",price: " + this.price; }
}
function dump(obj) {
var out = '';
for (var i in obj) {
if (typeof obj[i] === "object")
out += i + ": {\n" + dump(obj[i]) + "}\n";
else
out += i + ": " + obj[i] + "\n";
}
return out;
}
console.log(book);
console.log(dump(book));
</script>
沒有留言:
張貼留言