0
var str = 'foobar';
console.log( str[4] );

prints: 
a

这证明字符串也像数组一样。我正确吗?

4

1 回答 1

3

您不能在特定索引处设置字符,所以不,不是:

> var a = 'foo';
undefined
> a[0] = 'x';  // No warning, no error. It just silently fails.
"x"
> a
"foo"
于 2013-04-12T06:27:17.197 回答