JavaScript v.3.0中的Array和Hash(关联数组) [英] Array and Hash (Associative array) in JavaScript v.3.0

查看:64
本文介绍了JavaScript v.3.0中的Array和Hash(关联数组)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

无论你想知道什么,但总是害怕问。


< http://www.geocities.com/schools_ring/ArrayAndHash.html>

Whatever you wanted to know about it but always were affraid to ask.

<http://www.geocities.com/schools_ring/ArrayAndHash.html>

推荐答案

VK写道:
无论你想知道什么,但总是很害怕问。

< http://www.geocities.com/schools_ring/ArrayAndHash.html>
Whatever you wanted to know about it but always were affraid to ask.

<http://www.geocities.com/schools_ring/ArrayAndHash.html>




我认为你需要重新考虑你对阵列长度的评论(我的

评论包装):


" var arrayObject = new Array(3); // arrayObject有3个未定义

//元素"


在整篇文章中多次重复误解。


ECMA规范没有说长度属性是数组中元素的数量,它被定义为数字上比每个元素的名称大
名称为数组索引的属性

(这意味着它将等于最大索引加1或更大)。


出于所有实际目的,它是否无关:


var x = new Array(99);


实际上是否会创建一个包含99个元素的数组,但它确实如此

显式创建一个长度属性为99的数组。这就是

你可以肯定地说出来。


你似乎已经忽略了这里记录的广泛对话

,其中详细指出了上述内容:


< URL:http://groups.google .com.au /克oup / comp.lang.javascript / browse_frm / thread / c12423afa53a28f8 / 589d140d9290e7a9?q = array + length + undefined& rnum = 7& hl = en#589d140d9290e7a9>


最近有其他对话覆盖类似的地面。

您网页未提及的一个重要属性是,任何索引不小于长度的元素

都将被删除,所以如果你有

一个长度为10的数组并将其设置为1,索引为

1或更大的任何元素都将被删除。


- -

Rob



I think you need to reconsider your comments about array length (my
wrapping of comments):

"var arrayObject = new Array(3); // arrayObject has 3 undefined
// elements"

That misconception has been repeated many times throughout your article.

The ECMA specification does not say that the length property is the
number of elements in the array, it is defined as being numerically
greater than the name of every property whose name is an array index
(which means it will be equal to the largest index plus 1 or greater).

For all practical purposes, it is irrelevant whether:

var x = new Array( 99 );

actually creates an array of 99 elements or not, but it does
explicitly create an array with a length property of 99. And that is
all you can say with certainty.

You appear to have disregarded the extensive conversation logged here
where the above was pointed out in great detail:

<URL:http://groups.google.com.au/group/comp.lang.javascript/browse_frm/thread/c12423afa53a28f8/589d140d9290e7a9?q=array+length+undefined&rnum=7&h l=en#589d140d9290e7a9>

Other conversations have recently covered similar ground.
An important property not mentioned by your page is that any element
with an index not less than the length will be deleted, so if you have
an array with length 10 and you set it to 1, any element with index of
1 or greater is deleted.

--
Rob


>我想你需要重新考虑你对数组长度的评论(我的
> I think you need to reconsider your comments about array length (my
评论的包装):

var arrayObject = new Array(3); // arrayObject有3个未定义的
//元素"

在整篇文章中,这种误解已多次重复。


我试图与之斗争的错误概念(或简单的顽固性)确实已多次讨论过它的错误并证明它的错误是非常的/>
清楚地在文章中。我鼓励您再次访问:

< http://www.geocities.com/schools_ring/ArrayAndHash.html#Array_Length>

及以下,以及适用于您选择的其他阵列方法。


这种误解(让我们坚持这个较为柔和的术语)来自于低价的b $ b b b级别内存分配和高级别

编程实体行为。


正如我之前发布的那样,矩阵转换是

你的爱好(?)。特别是对你而言,理解你真正使用的是什么以及它将如何应对所应用的方法至关重要。

ECMA规范并未说出长度property是数组中元素的数量,它定义为数字大于名称为数组索引的每个属性的名称
(这意味着它将等于最大指数加1或更大。

对于所有实际目的,无论是否:

var x = new Array(99);
实际上是否创建了一个包含99个元素的数组,但它确实显式创建了一个长度属性为99的数组。这就是你可以肯定地说的所有内容。



< http://www.geocities.com/schools_ring/ArrayAndHash.html#Array_Length>

等等。读取灰色区域中的代码示例。 *读取它*,而不是

只是作为方法实现错误传递过来。


页面未提及的一个重要属性是任何元素
索引不小于长度将被删除,所以如果你有一个长度为10的数组并且你将它设置为1,那么索引为
1或更大的任何元素都将被删除。
wrapping of comments):

"var arrayObject = new Array(3); // arrayObject has 3 undefined
// elements"

That misconception has been repeated many times throughout your article.
The misconception (or a plain stubborness) I''m trying to fight with has
been indeed discussed many times and its wrongness is demonstrated very
clearly in the article. I encourage you to go through again of:
<http://www.geocities.com/schools_ring/ArrayAndHash.html#Array_Length>
and below, as well as apply other array methods of you choice.

This misconception (let''s stick to this softer term) erises from the
brute mix of the low level memory allocation and the high level
programming entity behavior.

As I may notice from your previous postings, the matrix transpoding is
your hobby(?). So especially for you it is vital to understand what are
you really working with and how will it respond to the applied methods.
The ECMA specification does not say that the length property is the
number of elements in the array, it is defined as being numerically
greater than the name of every property whose name is an array index
(which means it will be equal to the largest index plus 1 or greater).

For all practical purposes, it is irrelevant whether:

var x = new Array( 99 );

actually creates an array of 99 elements or not, but it does
explicitly create an array with a length property of 99. And that is
all you can say with certainty.

<http://www.geocities.com/schools_ring/ArrayAndHash.html#Array_Length>
and further. Read the code samples in the grayed area. *Read it* , not
just pass over as "a method implementation error".

An important property not mentioned by your page is that any element
with an index not less than the length will be deleted, so if you have
an array with length 10 and you set it to 1, any element with index of
1 or greater is deleted.



是的,如果你指定arrayObject = []那么所有元素将被删除。我不想在公开阅读中提到

Array.length可以用作强力ReDim(alloc)方法。什么

你不知道会不会伤害你:-)数组有足够的方法来支付
更优雅可靠地完成它。


Yes, as well is if you assign arrayObject = [] then all elements will
be removed. I did not want to mention in a public reading that the
Array.length can be used as a brute force ReDim (alloc) method. What
you don''t know will not hurt you :-) Array has enough methods to
accomplish it more gracefully and reliably.


有趣的文章。我被批评在我创建的脚本中使用数组类型为

a hash(排序):


Test = new function(){


var
Interesting Article. I have been criticized for using the array type as
a hash (sort of) in a script that I created:

Test = new function() {

var


这篇关于JavaScript v.3.0中的Array和Hash(关联数组)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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