[array / object]中的[literal]是什么意思? [英] What does [literal] in [array/object] mean?

查看:141
本文介绍了[array / object]中的[literal]是什么意思?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下语法是什么意思:

1 in [1,2,3,5]

我知道它不会在数组中搜索1。但是它做了什么?

I know it doesn't search for 1 in the array. But what does it do?

我看到它在循环中使用:

I've seen it used in loops:

for (var i in testArray)
{

}

但是也见过这个用它本身。这是否意味着检查文字是否是数组或对象中另一个操作数的有效索引?

But have also seen this used by itself. Does it mean check if the literal is a valid index in the array or object that is the other operand?

推荐答案

对象中的文字 表示:从对象获取属性文字

literalinobject means: "Get a property literal from object."

在循环中使用时,引擎会尝试访问对象的所有属性

When used in a loop, the engine will try to access all properties of the object.

1不会检查值为 1 ,但它会检查元素1( array [1] )是否存在。

1 in [1,2,3,4] doesn't check for an occurence of an element with a value of 1, but it checks whether element 1 (array[1]) exists or not.

这篇关于[array / object]中的[literal]是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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