数组对象的命名问题 [英] Naming problem on array object

查看:76
本文介绍了数组对象的命名问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个数组来存储一些学生信息,例如

var s = new Array(''2006001'',''Apple Joker'',''5B'');


通常情况下,我们使用s [0],s [1],s [2]得到数据......

如何定义它们更具可读性

s [''studentID''],s [''studentName''],s [''class'']?


谢谢

I have a array to store some student information, eg
var s = new Array(''2006001'', ''Apple Joker'', ''5B'');

normally, We get the data using s[0], s[1],s[2] ...
How can I define them more readable like
s[''studentID''], s[''studentName''], s[''class''] ?

Thank you

推荐答案

Cylix写道:
Cylix wrote:

我有一个数组存储一些学生信息,例如

var s = new Array(''2006001'',''Apple Joker'',''5B'');


通常,我们使用s [0],s [1],s [2]得到数据...

如何定义它们更具可读性如

s ['' studentID''],s [''studentName''],s [''class'']?
I have a array to store some student information, eg
var s = new Array(''2006001'', ''Apple Joker'', ''5B'');

normally, We get the data using s[0], s[1],s[2] ...
How can I define them more readable like
s[''studentID''], s[''studentName''], s[''class''] ?



创建一个Object而不是一个数组。

对象的行为类似于/是哈希。

例如:


var myClass = new Object();

myClass [" studentID"] = 123;

myClass [" ; studentName"] =" Cyclix";




问候,

Erwin Moller

Make an Object of it instead of an array.
Objects behave like / are hashes.
eg:

var myClass = new Object();
myClass["studentID"] = 123;
myClass["studentName"] = "Cyclix";
etc.

Regards,
Erwin Moller


>

谢谢
>
Thank you


> Erwin Moller写道:
>Erwin Moller wrote:

var myClass = new Object();

myClass [" studentID"] = 123;

myClass [" ; studentName"] =" Cyclix" ;;
var myClass = new Object();
myClass["studentID"] = 123;
myClass["studentName"] = "Cyclix";



首先感谢您的建议,

这样,

我还能使用myClass [0 ],myClass [1]得到的值?

Thank you for your suggestion first,
Under this way,
Can I still using myClass[0], myClass[1] to get the value?


Cylix写道:
Cylix wrote:

> Erwin Moller写道:
>Erwin Moller wrote:


> var myClass = new Object();
myClass [" ; studentID"] = 123;
myClass [" studentName"] =" Cyclix" ;;
>var myClass = new Object();
myClass["studentID"] = 123;
myClass["studentName"] = "Cyclix";



首先感谢您的建议,

这样,

我还可以使用myClass [0 ],myClass [1]得到的价值?


Thank you for your suggestion first,
Under this way,
Can I still using myClass[0], myClass[1] to get the value?



No.


对象属性只能有一个名称,即一个字符串。你可以将b $ b称为'0'','1'',''2'等等,但是你可以使用数组。


您应该查看有关如何使用

方括号和点符号访问属性的常见问题解答:


< URL:http:// www.jibbering.com/faq/#FAQ4_39>

-

Rob

No.

Object properties can only have one name, which is a string. You can
call them ''0'', ''1'', ''2'', etc. but then you might as well use an Array.

You should probably check the FAQ on how to access properties using
square brackets and dot notation:

<URL:http://www.jibbering.com/faq/#FAQ4_39>
--
Rob


这篇关于数组对象的命名问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆