Method js inner space string removed

function noSpace(x){
   if(x.match(/\s*/g)){
     return x.replace(/\s*/g,"");
   }else{
     return x;
   }
}

---

function noSpace(x){
  return x.replace(/\s/g, '');
}

---

function noSpace(x){
  var result = ""
  for(var index = 0; index < x.length; index++){
    if(x[index] !== " "){
      result += x[index];
    }
  }
  return result;
}

---

function noSpace(x){
   return x.replace(/ /g,'')
}

---

function noSpace(x){
  return x.split("")
    .map(function(val){
      return val == " "?"":val
    })
    .join("");
}

Guess you like

Origin www.cnblogs.com/ukzq/p/12033166.html
Recommended