我有:
var text = [];
text[0] = 'xyй';
text[0][0] = 'c';
alert(text[0][0]); // = 'xyй'
我认为有必要将字符串转换为数组吗?这是真的吗?
答案 0 :(得分:0)
以下两种方式: Live demo (click).
var text = [];
text[0] = 'xyй';
//break each string at each character into array
text[0] = text[0].split('');
//replace array item
text[0][0] = 'c';
//rejoin array into string
text[0] = text[0].join('');
console.log(text[0]);
var text = [];
text[0] = 'xyй';
//replace first character (character 0) with 'c'
text[0] = text[0].replace(text[0].charAt(0), 'c');
console.log(text[0]);