运算符[]和字符串(如charAt())

时间:2013-04-12 06:24:53

标签: javascript

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

prints: 
a

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

1 个答案:

答案 0 :(得分:3)

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

> var a = 'foo';
undefined
> a[0] = 'x';  // No warning, no error. It just silently fails.
"x"
> a
"foo"