我在下面有一个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']]
任何身体都可以帮助我。
答案 0 :(得分:3)
您可以将数组添加到数组的末尾:
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'];
答案 1 :(得分:0)
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");
这应该有助于使它更有活力。