javascript - Javascript替换在数组字符串元素中不起作用
问题描述
这是我的数组:
let model = ["xxx","xxx"];
我想用'o'替换数组第二个元素的字符串中的第二个'x'。
我试过这个:
let model = ["xxx", "xxx"];
console.log(model[1][2])
// -> output : x -> OK
model[1][2] = model[1][2].replace('x', 'o')
console.log(model);
// -> output : ["xxx", "xxx"] -> ???
我也试过这个:
let model = ["xxx", "xxx"];
console.log(model[1][2])
// -> output : x
model[1][2] = 'o'
console.log(model);
// -> output : ["xxx", "xxx"]
为什么不工作?谢谢 !
解决方案
推荐阅读
- r - 使用 ggsave 保存到 png 时,ggplot 会丢失 scale_color_manual
- r - API没有在循环中返回响应,但是当我单独执行时返回
- css - Next.js 不会在状态更改时重新渲染 UI
- reactjs - 使用 Portal 时出现 React Modal 和 Tooltip 问题
- dockerfile - dockerfile 将本地war文件添加到tomcat容器中
- php - 使用 wp_remote_post() 函数“不允许调用此方法”
- javascript - 有什么方法可以确定鼠标悬停在哪个角色上而不创建很多跨度?
- mysql - 如何在表格中获取 id 的上线
- python - 如何扩展基于类的视图
- python - 仅当值存在一次时应用命令