Problem creating array in javascript
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.
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'];
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.
精彩评论