Javascript Array
whats the problem with that array? var proImages = { {img_1 : '3648119884.png',img_2 : '2737618597.png',img_3 : '1688333623.png'}, {img_1 : '8738764911.png',img_2 : '1367341638.png
Solution 1:
You should use [a,b,c,...]
to create an array in Javascript, and {a:1, b:2, c:3, ...}
to create an Object (associative array).
var proImages = [ // <-----
{img_1 : '3648119884.png',img_2 : '2737618597.png',img_3 : '1688333623.png'},
...
{img_1 : '0.png',img_2 : '0.png',img_3 : '0.png'}]; // <------
Solution 2:
That's not an array, but an object. Use [
and ]
instead of {
and }
:
var proImages = [
{img_1 : '3648119884.png',img_2 : '2737618597.png',img_3 : '1688333623.png'},
{img_1 : '8738764911.png',img_2 : '1367341638.png',img_3 : '9613419473.png'},
{img_1 : '0072066717.png',img_2 : '2516072491.png',img_3 : '1567853878.png'},
{img_1 : '2991559225.png',img_2 : '8333423763.png',img_3 : '8057162573.png'},
{img_1 : '7136719769.png',img_2 : '1881889542.png',img_3 : '5844323517.png'},
{img_1 : '7993931084.png',img_2 : '6991377670.png',img_3 : '3310663052.png'},
{img_1 : '3361259627.png',img_2 : '2221673184.png',img_3 : '9499134393.png'},
{img_1 : '7647189195.png',img_2 : '8252917294.png',img_3 : '5475029195.png'},
{img_1 : '4546336022.png',img_2 : '9378256077.png',img_3 : '5624264738.png'},
{img_1 : '5969572723.png',img_2 : '9878662191.png',img_3 : '9260704536.png'},
{img_1 : '5307173138.png',img_2 : '5915393636.png',img_3 : '0393696135.png'},
{img_1 : '3890469821.png',img_2 : '5722291935.png',img_3 : '1776314584.png'},
{img_1 : '5105921436.png',img_2 : '2969844375.png',img_3 : '0879713286.png'},
{img_1 : '8923771834.png',img_2 : '3176446381.png',img_3 : '4669049321.png'},
{img_1 : '7973191654.png',img_2 : '5472865178.png',img_3 : '7881294714.png'},
{img_1 : '0801773822.png',img_2 : '8424418951.png',img_3 : '1923419282.png'},
{img_1 : '0.png',img_2 : '0.png',img_3 : '0.png'}];
Solution 3:
In javascript all arrays are objects but not all objects are arrays - well sort of :).
You object as declared is invalid.
You can iterate an object as well as an object but it is done differently. One issue is that this is not really even an object as declared. SO you need to declare it differently.
Access example is included in each;
With an inner array: proImages.myobj[5].img_1
var proImages = {myobj:[ {
img_1: '3648119884.png',
img_2: '2737618597.png',
img_3: '1688333623.png'
}, {
img_1: '8738764911.png',
img_2: '1367341638.png',
img_3: '9613419473.png'
}, {
img_1: '0072066717.png',
img_2: '2516072491.png',
img_3: '1567853878.png'
}, {
img_1: '2991559225.png',
img_2: '8333423763.png',
img_3: '8057162573.png'
}, {
img_1: '7136719769.png',
img_2: '1881889542.png',
img_3: '5844323517.png'
}, {
img_1: '7993931084.png',
img_2: '6991377670.png',
img_3: '3310663052.png'
}, {
img_1: '3361259627.png',
img_2: '2221673184.png',
img_3: '9499134393.png'
}, {
img_1: '7647189195.png',
img_2: '8252917294.png',
img_3: '5475029195.png'
}, {
img_1: '4546336022.png',
img_2: '9378256077.png',
img_3: '5624264738.png'
}, {
img_1: '5969572723.png',
img_2: '9878662191.png',
img_3: '9260704536.png'
}, {
img_1: '5307173138.png',
img_2: '5915393636.png',
img_3: '0393696135.png'
}, {
img_1: '3890469821.png',
img_2: '5722291935.png',
img_3: '1776314584.png'
}, {
img_1: '5105921436.png',
img_2: '2969844375.png',
img_3: '0879713286.png'
}, {
img_1: '8923771834.png',
img_2: '3176446381.png',
img_3: '4669049321.png'
}, {
img_1: '7973191654.png',
img_2: '5472865178.png',
img_3: '7881294714.png'
}, {
img_1: '0801773822.png',
img_2: '8424418951.png',
img_3: '1923419282.png'
}, {
img_1: '0.png',
img_2: '0.png',
img_3: '0.png'
}
]
};
AS an array: proImages[5].img_2
var proImages = {myarray[
{
img_1: '3648119884.png',
img_2: '2737618597.png',
img_3: '1688333623.png'
}, {
img_1: '8738764911.png',
img_2: '1367341638.png',
img_3: '9613419473.png'
}, {
img_1: '0072066717.png',
img_2: '2516072491.png',
img_3: '1567853878.png'
}, {
img_1: '2991559225.png',
img_2: '8333423763.png',
img_3: '8057162573.png'
}, {
img_1: '7136719769.png',
img_2: '1881889542.png',
img_3: '5844323517.png'
}, {
img_1: '7993931084.png',
img_2: '6991377670.png',
img_3: '3310663052.png'
}, {
img_1: '3361259627.png',
img_2: '2221673184.png',
img_3: '9499134393.png'
}, {
img_1: '7647189195.png',
img_2: '8252917294.png',
img_3: '5475029195.png'
}, {
img_1: '4546336022.png',
img_2: '9378256077.png',
img_3: '5624264738.png'
}, {
img_1: '5969572723.png',
img_2: '9878662191.png',
img_3: '9260704536.png'
}, {
img_1: '5307173138.png',
img_2: '5915393636.png',
img_3: '0393696135.png'
}, {
img_1: '3890469821.png',
img_2: '5722291935.png',
img_3: '1776314584.png'
}, {
img_1: '5105921436.png',
img_2: '2969844375.png',
img_3: '0879713286.png'
}, {
img_1: '8923771834.png',
img_2: '3176446381.png',
img_3: '4669049321.png'
}, {
img_1: '7973191654.png',
img_2: '5472865178.png',
img_3: '7881294714.png'
}, {
img_1: '0801773822.png',
img_2: '8424418951.png',
img_3: '1923419282.png'
}, {
img_1: '0.png',
img_2: '0.png',
img_3: '0.png'
}
];
Or As a series of objects (well one really with inner objects: proImages.myobj4.img_2
varproImages=
{ myobj1: {img_1:'3648119884.png', img_2:'2737618597.png', img_3:'1688333623.png'
}, myobj2: {img_1:'8738764911.png', img_2:'1367341638.png', img_3:'9613419473.png'
}, myobj3: {img_1:'0072066717.png', img_2:'2516072491.png', img_3:'1567853878.png'
}, myobj4: {img_1:'2991559225.png', img_2:'8333423763.png', img_3:'8057162573.png'
}, myobj5: {img_1:'7136719769.png', img_2:'1881889542.png', img_3:'5844323517.png'
}, myobj6: {img_1:'7993931084.png', img_2:'6991377670.png', img_3:'3310663052.png'
}, myobj7: {img_1:'3361259627.png', img_2:'2221673184.png', img_3:'9499134393.png'
}, myobj8: {img_1:'7647189195.png', img_2:'8252917294.png', img_3:'5475029195.png'
}, myobj9: {img_1:'4546336022.png', img_2:'9378256077.png', img_3:'5624264738.png'
}, myobj10: {img_1:'5969572723.png', img_2:'9878662191.png', img_3:'9260704536.png'
}, myobj11: {img_1:'5307173138.png', img_2:'5915393636.png', img_3:'0393696135.png'
}, myobj12: {img_1:'3890469821.png', img_2:'5722291935.png', img_3:'1776314584.png'
}, myobj13: {img_1:'5105921436.png', img_2:'2969844375.png', img_3:'0879713286.png'
}, myobj14: {img_1:'8923771834.png', img_2:'3176446381.png', img_3:'4669049321.png'
}, myobj15: {img_1:'7973191654.png', img_2:'5472865178.png', img_3:'7881294714.png'
}, myobj16: {img_1:'0801773822.png', img_2:'8424418951.png', img_3:'1923419282.png'
}, myobj17: {img_1:'0.png',img_2:'0.png', img_3:'0.png'
}
};
Post a Comment for "Javascript Array"