gpt4 book ai didi

javascript - 如何在javascript for循环中打印大括号

转载 作者:行者123 更新时间:2023-12-02 14:54:56 28 4
gpt4 key购买 nike

我想知道如何为这种类型的代码添加for循环。请忘记 title、start、backgroundColorborderColor 值。我可以使用 for 循环加载它们。我想知道如何添加一个循环来打印这一切。

events: [
{
title: 'All Day Event',
start: new Date(y, m, 1),
backgroundColor: "#f56954", //red
borderColor: "#f56954" //red
},
{
title: 'Long Event',
start: new Date(y, m, d - 5),
end: new Date(y, m, d - 2),
backgroundColor: "#f39c12", //yellow
borderColor: "#f39c12" //yellow
},
{
title: 'Meeting',
start: new Date(y, m, d, 10, 30),
allDay: false,
backgroundColor: "#0073b7", //Blue
borderColor: "#0073b7" //Blue
},
{
title: 'Lunch',
start: new Date(y, m, d, 12, 0),
end: new Date(y, m, d, 14, 0),
allDay: false,
backgroundColor: "#00c0ef", //Info (aqua)
borderColor: "#00c0ef"//Info (aqua)
},
{
title: 'Birthday Party',
start: new Date(y, m, d + 1, 19, 0),
end: new Date(y, m, d + 1, 22, 30),
allDay: false,
backgroundColor: "#00a65a", //Success (green)
borderColor: "#00a65a" //Success (green)
},
{
title: 'Click for Google',
start: new Date(y, m, 28),
end: new Date(y, m, 29),
url: 'http://google.com/',
backgroundColor: "#3c8dbc", //Primary (light-blue)
borderColor: "#3c8dbc" //Primary (light-blue)
},
],

最佳答案

如果所有元素都有单独的数组(title[]、start[]、end[] 等),那么您可以尝试下面的方法

 var main_array = [];

for (var i = 0; i < title.length; i++) {

main_array.push({
"title" : title[i],
"start" : start[i],
"end" : end[i],
"allDay" : allDay[i],
"backgroundColor" : backgroundColor[i],
"borderColor" : borderColor[i]
});

}

关于javascript - 如何在javascript for循环中打印大括号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35883568/

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