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..."}
 ];
} 
asked Mar 25, 2014 at 1:10
0

1 Answer 1

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);
answered Mar 25, 2014 at 1:10
Sign up to request clarification or add additional context in comments.

1 Comment

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?

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.