本文介绍了如何在 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 中追加或连接字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!
本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!