0

lets say i want an array with a tag name so when i want a specific row i can call it with its tag name, ie myArray['tag_one'][2] for the tag_one tag i want the 3rd element.

So is there a way i can achieve this?

something like :

var myArray=[
        tag_one=[1,2,3],
        tag_two=[11,22,33],
        tag_three=[111,222,333]
] 

excuse my bad English, thx in advanced

1 Answer 1

3

You can use an object literal:

var myObject = {
    tag_one: [1,2,3],
    tag_two: [11,22,33],
    tag_three: [111,222,333]
}; 

// Using bracket notation:
alert(myObject["tag_one"][0]);  //-> 1

// Using dot notation:
alert(myObject.tag_two[0]);  //-> 11
Sign up to request clarification or add additional context in comments.

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.