gpt4 book ai didi

JavaScript 语法问题 : [{ }] hierarchy

转载 作者:行者123 更新时间:2023-11-28 19:52:32 27 4
gpt4 key购买 nike

我遇到了以下嵌套数组,并且对它为什么使用这种特定语法有点困惑:

var allQuestions = [{
question: "Which company first implemented the JavaScript language?",
choices: ["Microsoft Corp.", " Sun Microsystems Corp.", "Netscape Communications Corp."],
correctAnswer: 2
}];

完整示例:http://jsfiddle.net/alxers/v9t4t/

使用是常见的做法吗 [{...}]已经声明了这样一个变量吗?

最佳答案

定义是一个包含对象文字的数组。它并不是真正的嵌套数组。

{
question: "Which company first implemented the JavaScript language?",
choices: ["Microsoft Corp.", " Sun Microsystems Corp.", "Netscape Communications Corp."],
correctAnswer: 2
}

是一个对象文字,您的数组包含它。在您链接到的 fiddle 中,有几个在 allQuestions 数组中定义。通过这样做,可以轻松循环问题数组并依次显示每个问题。

关于JavaScript 语法问题 : [{ }] hierarchy,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23181025/

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