在javascript中创建数组时出现问题

发布于 2024-11-27 19:21:31 字数 548 浏览 1 评论 0原文

我下面有一个 JavaScript 代码。

bgCustom = { 'items':[], 'items_num':3, 'element':'#bg_custom_thumbs', 'next': '#bg_custom_next_thumb', 'prev': '#bg_custom_prev_thumb', 'width':165 };
//populate array
bgCustom.items = [["images/backgrounds/bear-ears_thumb.jpg", "bear-ears.jpg", "Bear-Hair"], ["images/backgrounds/blue-swirls_thumb.jpg", "blue-swirls.jpg", "WaterSmoke"]];

我如何动态创建 bgCustom.items 数组。意味着我想要一个数组列表

[['val1_1','val1_2','val1_3'],['val2_1','val2_2','val2_3']]

任何人都可以帮助我吗?

i have a javascript code below.

bgCustom = { 'items':[], 'items_num':3, 'element':'#bg_custom_thumbs', 'next': '#bg_custom_next_thumb', 'prev': '#bg_custom_prev_thumb', 'width':165 };
//populate array
bgCustom.items = [["images/backgrounds/bear-ears_thumb.jpg", "bear-ears.jpg", "Bear-Hair"], ["images/backgrounds/blue-swirls_thumb.jpg", "blue-swirls.jpg", "WaterSmoke"]];

ho do i create bgCustom.items array dynamic. means i want a array list

[['val1_1','val1_2','val1_3'],['val2_1','val2_2','val2_3']]

Can any body help me.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

飘落散花 2024-12-04 19:21:31

您可以将数组添加到数组末尾:

bgCustomer.items.push(['val1_1','val1_2','val1_3']);
bgCustomer.items.push(['val2_1','val2_2','val2_3']);

您还可以在特定索引处分配数组。如果您使用超出当前大小的索引,数组将自动扩展:

bgCustomer.items[0] = ['val1_1','val1_2','val1_3'];
bgCustomer.items[1] = ['val2_1','val2_2','val2_3'];

You can add arrays to the end of the array:

bgCustomer.items.push(['val1_1','val1_2','val1_3']);
bgCustomer.items.push(['val2_1','val2_2','val2_3']);

You can also assign arrays at specific indexes. The array will automatically expand if you use an index outside the current size:

bgCustomer.items[0] = ['val1_1','val1_2','val1_3'];
bgCustomer.items[1] = ['val2_1','val2_2','val2_3'];
烟酒忠诚 2024-12-04 19:21:31
bgCustom = { 'items':[], 'items_num':3, 'element':'#bg_custom_thumbs', 'next': '#bg_custom_next_thumb', 'prev': '#bg_custom_prev_thumb', 'width':165 };

function PushToItems(a,b,c) {
    var ar = [a,b,c];
    bgCustom.items.push(ar);
}

PushToItems("images/backgrounds/bear-ears_thumb.jpg", "bear-ears.jpg", "Bear-Hair");

这应该可以让它变得更有活力。

bgCustom = { 'items':[], 'items_num':3, 'element':'#bg_custom_thumbs', 'next': '#bg_custom_next_thumb', 'prev': '#bg_custom_prev_thumb', 'width':165 };

function PushToItems(a,b,c) {
    var ar = [a,b,c];
    bgCustom.items.push(ar);
}

PushToItems("images/backgrounds/bear-ears_thumb.jpg", "bear-ears.jpg", "Bear-Hair");

That should work for making it a little more dynamic.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文