How to append or concat strings in Javascript?(如何在 Javascript 中追加或连接字符串?)
问题描述
所以我试图添加到一个字符串,它显示为空.
So I'm trying to add to a string and it shows up as empty.
var DNA = "TAG";
var mRNA = "";
m_RNA()
function check(a, b, string) {
if (string = a) {
mRNA.concat(b);
}
}
function m_RNA(){
//console.log(DNA)
for (var i = 0; i < DNA.length; i++) {
console.log("Checking: " + DNA[i]);
check("T", "A", DNA[i]);
check("A", "U", DNA[i]);
check("C", "G", DNA[i]);
check("G", "C", DNA[i]);
console.log(mRNA);
}
}
它应该在控制台中显示 AUC,但它只是空白.顺便说一下,这是通过 Firefox 实现的.
Its supposed to show AUC in the console but its just blank. This is through firefox by the way.
推荐答案
mRNA.concat(b);
不会改变字符串,它只会计算值.您需要mRNA = mRNA.concat(b)
(或mRNA = mRNA + b
)来改变mRNA
的值.
mRNA.concat(b);
doesn't mutate the string, it only computes the value. You need tomRNA = mRNA.concat(b)
(or mRNA = mRNA + b
) to change the value of mRNA
.
这篇关于如何在 Javascript 中追加或连接字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何在 Javascript 中追加或连接字符串?


基础教程推荐
- 什么是不使用 jQuery 的经验技术原因? 2022-01-01
- 如何使用 CSS 显示和隐藏 div? 2022-01-01
- 如何在特定日期之前获取消息? 2022-01-01
- WatchKit 支持 html 吗?有没有像 UIWebview 这样的控制器? 2022-01-01
- jQuery File Upload - 如何识别所有文件何时上传 2022-01-01
- Node.js 有没有好的索引/搜索引擎? 2022-01-01
- 为什么我在 Vue.js 中得到 ERR_CONNECTION_TIMED_OUT? 2022-01-01
- 如何使用sencha Touch2在单页中显示列表和其他标签 2022-01-01
- 每次设置弹出窗口的焦点 2022-01-01
- Javascript 在多个元素上单击事件侦听器并获取目标 2022-01-01