本文介绍了如何在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中附加或连接字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!