0

I want to return a multiply dimensional array from a function like so but I must be writing it wrong, I cant figure out whats wrong. I want to have key and value pairs.

function Multidimensional(){

    return [ 
        "one": [
            "two":[],
            "three":[
                "testing.png":{source:"http..."}
            ],
        "another.png": {source:"http..."}
    ];
} 
Kivylius
  • 6,357
  • 11
  • 44
  • 71

1 Answers1

3

If you want to have key/value pairs, you should use an object.

function Multidimensional(){

    return { 
        "one": {
            "two":[],
            "three":{
                "testing.png":{source:"http..."}
            },
        "another.png": {source:"http..."}
    };
} 

You can access the returned data like so:

var data = Multidimensional();
console.log(data['another.png']);
// or
console.log(data.one);
SomeKittens
  • 38,868
  • 19
  • 114
  • 143
  • Ok but when i'm looping true the object how can I determine witch one has a source/end from one that's a hierarchy? – Kivylius Mar 25 '14 at 01:14