0

Is their any way to create mutidimensional arrays in Javascript with Non Numeric Idex?

like the structure

                optionList[0]['id'] = "equals"; 
                optionList[0]['name'] = "Equals";

                optionList[1]['id'] = "not_equals_str"; 
                optionList[1]['name'] = "Does Not Equal";

                optionList[2]['id'] = "contains"; 
                optionList[2]['name'] = "Contains";

5 Answers 5

2

Yes, at least some kind of object that will do what you want even if it's not really a "multidimensional array".

You create a mododimensionnal array.

And you populate it with simple javascript objects, which you can consider as some kind of maps for many purposes.

var optionList = [];
optionList.push({});
optionList[0]['id'] = "equals"; 
...

You can create it in one go :

var optionList = [
    {id:"equals", name:"Equals"},
    ...
];
Sign up to request clarification or add additional context in comments.

Comments

2

In JavaScript you should use objects as arrays with non numeric indices. So your structure will look as follows:

var optionList = [
    {
        id : "equals",
        name : "Equals"
    },
    {
        id : "not_equals_str",
        name : "Does Not Equal"
    },
    {
        id : "contains",
        name : "Contains"
    }
];

1 Comment

This is not exactly a multidimensional array, but an array of objects.
0

Those are arrays that contain objects. It would look like this:

var optionList = [
    {},
    {},
    {}
];

Comments

0

Yes You can always have nesting of Objects.

optionList = [{
      id: "equals",
      name: "Equals"
   },{
      id: "not_equals_str",
      name: "Does not Equal"
   },{
      id: "contains",
      name: "Contains"
   }]

Comments

0

Yes. You have to define an empty array and then push those details as object into it.

 var optionList = [];
 optionList.push({id: 'equals', name: 'equals'});
 optionList.push({id: 'not_equals_str', name: 'Does Not Equal'});

Hope this helps.

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.