JavaScript Array Problem

Posted by JasonS on Stack Overflow See other posts from Stack Overflow or by JasonS
Published on 2010-05-11T07:59:55Z Indexed on 2010/05/11 8:04 UTC
Read the original article Hit count: 282

Filed under:
|
|

Hi,

This wasn't the question I was going to ask but I have unexpectedly run aground with JavaScript arrays. I come from a PHP background and after looking at a few websites I am none the wiser.

I am trying to create a multi-dimensional array.

var photos = new Array;
var a = 0;
$("#photos img").each(function(i) {
    photos[a]["url"] = this.src;
    photos[a]["caption"] = this.alt;
    photos[a]["background"] = this.css('background-color');
    a++;
});

Error message: photos[a] is undefined. How do I do this. Thanks.

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about jQuery