Javascript filter common words out of a string

I am trying to filter any common words out of a string. I found this code on the internet, and it looks like it will work perfect but how do I modify it to not return a string with ','? ---- Current code: function getUncommon(cquerySearch, filterCommonWords) { var wordArr = sentence.match(/\w+/g), commonObj = {}, uncommonArr = [], word, i; common = common.split(','); for ( i = 0; i < common.length; i++ ) { commonObj[ common[i].trim() ] = true; } for ( i = 0; i < wordArr.length; i++ ) { word = wordArr[i].trim().toLowerCase(); if ( !commonObj[word] ) { uncommonArr.push(word); } } return uncommonArr; } ---- This returns an array like `uncommonArr = 'Return, String, Would, Go, Here'`. Thanks for any help!
I'm not sure I understand, but can you replace the line return uncommonArr with return uncommonArr.join(' ')?

以上就是Javascript filter common words out of a string的详细内容,更多请关注web前端其它相关文章!

赞(0) 打赏
未经允许不得转载:web前端首页 » JavaScript 答疑

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

前端开发相关广告投放 更专业 更精准

联系我们

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏