gpt4 book ai didi

javascript - 当对象深度嵌套在 JavaScript 中时,如何将整个对象作为输出?

转载 作者:行者123 更新时间:2023-11-30 20:16:04 26 4
gpt4 key购买 nike

 let common = {
"id": 1364184,
"url": "http:\/\/www.tvmaze.com\/episodes\/1364184\/the-big-bang-
theory-11x12-the-matrimonial-metric",
"name": "The Matrimonial Metric",
"season": 11,
"number": 12,
"airdate": "2018-01-04",
"airtime": "20:00",
"airstamp": "2018-01-05T01:00:00+00:00",
"runtime": 30,
"image": {
"medium": "sonie",
"original": "agarwal"
},
"summary": "<p>To discover who would be most qualified to be best
man and maid of honor at their wedding, Sheldon and Amy subject
their friends to a series of secret experiments. Also, Penny
reveals her true feelings about Amy.<\/p>",
"_links": {
"self": {
"href": "http:\/\/api.tvmaze.com\/episodes\/1364184"
}
}
}
for (var x in common) {
console.log(x+ "=" +common[x]);
if ( x === "image" ){
let z = common.image
for (var y in z) {
console.log( x + " = " + y+ " : " +z[y]);
}
}if ( x === "_links" ){
let z = common._links.self
for (var y in z) {
console.log( x + " = " + y+ " : " +z[y]);
}
}
}

output is posted in the image

我写了大部分用于获取输出的代码,但我想要的是,摆脱图中显示的一些用黑色框起来的输出。所以请帮我...

最佳答案

如果您只是想将深度嵌套的对象作为字符串获取,您可以执行以下操作:JSON.stringify(值)

例如:

var value = {
one: {
two: {
three: [
'one',
'two',
'three'
]
}
}
}
var asString = JSON.stringify(value);

console.log(asString) # "{"one":{"two":{"three":["one","two","three"]}}}"

关于javascript - 当对象深度嵌套在 JavaScript 中时,如何将整个对象作为输出?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51911251/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com