0

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.

6
  • What do you mean by 'dynamic'? Commented Aug 4, 2011 at 13:52
  • how do i creat this type of array [['val1_1','val1_2','val1_3'],['val2_1','val2_2','val2_3']] Commented Aug 4, 2011 at 13:53
  • 1
    I don't see what the problem is, everything you've done should work. Commented Aug 4, 2011 at 13:53
  • yes but right now bgCustom.items is static values i want dynamic values Commented Aug 4, 2011 at 13:54
  • Still not clear what you mean by saying static or dynamic. In that array you can push values, remove values, change values... so what exactly are you trying to achieve? Commented Aug 4, 2011 at 13:57

2 Answers 2

2

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'];
Sign up to request clarification or add additional context in comments.

Comments

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");

That should work for making it a little more dynamic.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.