2次迭代 - 不同的结果 - 为什么? [英] 2 iterations - different results - why?

查看:78
本文介绍了2次迭代 - 不同的结果 - 为什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,


有谁能告诉我为什么这两组代码会给出不同的结果?


for(J in Next){

< action>

}

< function>

for(J = 0; J< Next 。长度; ++ J){

<与上述动作相同>

}

<与上述功能相同>


我想更改第二个版本,以便它给出与第一个版本相同的

结果。


任意想法好吗?!


干杯


Geoff

Hello,

Can anyone tell me why these 2 sets of code give different results?

for (J in Next) {
<action>
}
<function>
for (J=0;J<Next.length;++J) {
<same action as above>
}
<same function as above>

I would like to change the second version so that it gives the same
results as the first one.

Any ideas please?!

Cheers

Geoff

推荐答案

Geoff Cox< gc ** @ freeuk.notcomwrites:
Geoff Cox <gc**@freeuk.notcomwrites:

您好,


任何人都可以告诉为什么这两组代码给出了不同的结果?


for(J in Next){

< action>

}

< function>


for(J = 0; J< Next.length; ++ J){

<与上述相同的动作>

}

<与上面相同的功能>


我想更改第二个版本,以便它给出相同的

结果作为第一个。


有什么想法吗?!
Hello,

Can anyone tell me why these 2 sets of code give different results?

for (J in Next) {
<action>
}
<function>
for (J=0;J<Next.length;++J) {
<same action as above>
}
<same function as above>

I would like to change the second version so that it gives the same
results as the first one.

Any ideas please?!



他们完全不一样。使用第一个版本。


-

Joost Diepenmaat |博客: http://joost.zeekat.nl/ |工作: http://zeekat.nl/

They''re not the same at all. Use the first version.

--
Joost Diepenmaat | blog: http://joost.zeekat.nl/ | work: http://zeekat.nl/

2008年4月19日星期六23:05:10 +0200,Joost Diepenmaat< jo *** @ zeekat.nl>

写道:
On Sat, 19 Apr 2008 23:05:10 +0200, Joost Diepenmaat <jo***@zeekat.nl>
wrote:

> Geoff Cox< gc ** @ freeuk.notcomwrites:
>Geoff Cox <gc**@freeuk.notcomwrites:

>你好,

可以有谁告诉我为什么这两组代码给出了不同的结果?

for(J in Next){
< action>
}
< function>

for(J = 0; J< Next.length; ++ J){
<与上述相同的动作>
}
<与上述相同的功能> ;

我想改变第二个版本,以便它给出与第一个版本相同的结果。

请问任何想法?!
>Hello,

Can anyone tell me why these 2 sets of code give different results?

for (J in Next) {
<action>
}
<function>
for (J=0;J<Next.length;++J) {
<same action as above>
}
<same function as above>

I would like to change the second version so that it gives the same
results as the first one.

Any ideas please?!


他们根本不一样。使用第一个版本。


They''re not the same at all. Use the first version.



Joost,


我很乐意这样做,但它会导致与prototype.js发生冲突

库我被告知for / in进程可以处理属性

对象而不是某些Javscript实现中的元素...


你能告诉我它有什么区别吗?


干杯


Geoff

Joost,

I would love to do so but it causes a conflict with the prototype.js
library as I''m told that the for/in process can deal with properties
of objects rather than elements in some Javscript implementations...

Can you tell me what the difference is/are?

Cheers

Geoff


4月20日凌晨1点02分,Geoff Cox< g ... @ freeuk.notcomwrote:
On Apr 20, 1:02 am, Geoff Cox <g...@freeuk.notcomwrote:

你好,


谁能告诉我为什么这两组代码给出不同的结果?


for(J in Next){
Hello,

Can anyone tell me why these 2 sets of code give different results?

for (J in Next) {



枚举Next对象的属性,包括但不限于

数组元素 - 给定Next instanceof Array。


var Next = [1 ,2,3];

Next.foo =''bar;


for(var p in Next){

//将找到四个元素:

// 1,2,3, ''bar''

}

enumerates properties of Next object including but not limited by
array elements - given that Next instanceof Array.

var Next = [1,2,3];
Next.foo = ''bar;

for (var p in Next) {
// will find four elements:
// 1, 2, 3, ''bar''
}


< function>


for(J = 0; J< Next.length; ++ J){
<function>

for (J=0;J<Next.length;++J) {



枚举数组元素给定Next instanceof Array


var Next = [1,2,3];

Next.foo =''bar;


for(var p in Next){

//将找到三个元素:

// 1,2,3

//''bar''不是数组元素

//所以没有枚举

}

enumerates array elements given that Next instanceof Array

var Next = [1,2,3];
Next.foo = ''bar;

for (var p in Next) {
// will find three elements:
// 1, 2, 3
// ''bar'' is not an array element
// so not enumerated
}


我想更改第二个版本所以它给出与第一个相同的结果。
I would like to change the second version so that it gives the same
results as the first one.



这是不可能的,我只是解释了原因。

It is not possible and I just explained why.


这篇关于2次迭代 - 不同的结果 - 为什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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