在JavaScript中,可以像以下方式对对象和数组的值进行索引:objOrArray[index]
。是否存在一个唯一的“index”值?
换句话说:
是否存在一个值x
,使得以下语句始终为真?
let a = [1, 2, 3, 4];
/* Is this true? */ a[x] == a
let b = { a: 1, b: 2, c: 3 };
/* Is this true? */ b[x] == b
在这个上下文中,“identity”(身份)的定义是: https://en.wikipedia.org/wiki/Identity_function
a = [1,2,3]; a.myself = a; x = "myself"; a[x] === a
..(仅当x的值为所示时,才为真)。 - user2864740substr
方法已经被弃用,请不要使用该方法。其次,s.description.substring(0, 50)
不需要进行length
检查。我不明白“identity”在这里有什么作用。这不再是属性访问,而是条件运算符——两个完全不同的运算符。 - Sebastian Simon