undefinedfix
Sign in

String filtering problem

GertVW edited in Fri, 12 Nov 2021

Code clearly written in the filter string space code, why not take effect

图片描述

4 Replies
vnrmi
commented on Fri, 12 Nov 2021

var newStr="abc def ghi";

console.log(newStr.replace(/\s/g,""));
openHBP
commented on Fri, 12 Nov 2021

Most functions do not modify themselves, such as. Split() and. Replace(). So you should:

item.summary = item.summary.split(' ').join('');
item.summary = item.summary.replace(/.../g, '');
Yasir
commented on Sat, 13 Nov 2021

@Meathl is right, but there may be another reason why you don't have the effect is that you use Vue

let summary = item.summary.split(' ').join('');
summary = summary.replace(/(^\s*)|(\s*$)/g, "");
Vue.set(item,"summary",summary);
Rickard
commented on Sat, 13 Nov 2021

Strings are immutable

lock This question has been locked and the reply function has been disabled.