Nabil Ghulam
Nabil Ghulam

Reputation: 23

Search with a variable in array

I am trying to search an array with a variable, which seems to not work because it thinks the variable itself is a value.

var variable = "create";

var navViews = {
    "create" : [
        {
            "id"        : "1",
            "name"      : "Create",
            "urlext"    : "stylecreator"
        }
    ]
}
navViews.variable;

How do I reach "create" through a variable?

Upvotes: 0

Views: 61

Answers (1)

RIYAJ KHAN
RIYAJ KHAN

Reputation: 15290

If you want to get create array, you can do this in this way:

navViews[variable]

Upvotes: 2

Related Questions