码迷,mamicode.com
首页 > Web开发 > 详细

js将字符串内空格去除的方法

时间:2019-12-13 09:22:58      阅读:90      评论:0      收藏:0      [点我收藏+]

标签:match   UNC   ++   +=   class   return   for   ==   split   

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("");
}

js将字符串内空格去除的方法

标签:match   UNC   ++   +=   class   return   for   ==   split   

原文地址:https://www.cnblogs.com/ukzq/p/12033166.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!