简体   繁体   English

函数中的Javascript数组创建

[英]Javascript array creation in function

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: 我对Java语言不是很熟悉,并且遇到了一些我到目前为止找不到答案的东西,请看下面的代码:

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)? 每个字符串(11、1和4)后面的数字是什么意思? How would I retrieve a value from this kind of array? 我将如何从这种数组中检索值?

Thanks. 谢谢。

In this line : 在这一行:

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

this.defn is a json object which contains keys : this.defn是一个包含密钥的json对象

gridText , gridProp , gridTime gridText,gridProp,gridTime

These keys are json Arrays with two values in it . 这些键是json数组,其中有两个值。

If you want to get values of gridText , you can get it like this : 如果要获取gridText的值, 可以这样获得:

this.defn.gridText[0] // it will return 'aString1'
this.defn.gridText[1] // it will return 11

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.defn.gridText This will return you array ['aString1', 11] 这将返回数组['aString1', 11]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM