0

I'm not very familiar with Javascript and have come across something that I can't find an answer to so far, looking at the following code:

function gridWindow(visible) {
    this.name='grid';
    this.visible=visible;
    this.defn={ gridText: ['aString1', 11], gridProp: ['aString2', 1], gridTime: ['aString3', 4] };
    this.init();
}

My question is what is happening with this line from above:

this.defn={ gridText: ['aString1', 11], gridProp: ['aString2', 1], gridTime: ['aString3', 4] };

Is it creating an array? What do the numbers mean after each string (the 11, 1 and 4)? How would I retrieve a value from this kind of array?

Thanks.

3
  • 2
    It is creating an array... but I don't think we will be able to answer what are those numbers means without seeing how it is used Commented Aug 20, 2015 at 4:40
  • { gridText: ['aString1', 11] } creates a Javascript object with a property called gridText that has as its value an array with two entries. What the numbers mean is impossible to say. Commented Aug 20, 2015 at 4:43
  • Take a look at the init function that is being called. It probably access these values in this.defn. Commented Aug 20, 2015 at 4:44

2 Answers 2

1

In this line :

this.defn={ gridText: ['aString1', 11], gridProp: ['aString2', 1], gridTime: ['aString3', 4] };

this.defn is a json object which contains keys :

gridText , gridProp , gridTime

These keys are json Arrays with two values in it .

If you want to get values of gridText , you can get it like this :

this.defn.gridText[0] // it will return 'aString1'
this.defn.gridText[1] // it will return 11
Sign up to request clarification or add additional context in comments.

Comments

0

its not array, it is and object with key value pairs and values are arrays

you can get the value as this.defn.gridText. This will return you array ['aString1', 11]

1 Comment

or this.defn.gridText[1] to get at the 11.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.