如何在 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 =...

所以我试图添加到一个字符串,它显示为空.

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.

阅读全文

相关推荐

最新文章