我可以调用什么来过滤字符串结果

时间:2016-11-06 04:20:37

标签: javascript

如果我创建这样的条件语句,它可以工作:

if (this.category === 'male') {
    console.log('Male');
    this.query = this.query.substr(1, 3);
}

但是我可以使用什么来过滤字符串上的数字定位,而不是实际字符?我想评估“this.query”,这是一个字符串,并根据包含的某些字符进行过滤。我不能在字符串上调用filter,那么我可以使用什么?我不想只评估它,我想根据那里的那些系列字符返回新的结果。这让我逃避。

1 个答案:

答案 0 :(得分:1)

如果正确解释问题,您可以使用String.prototype.match()

if (this.category === 'male') {
    console.log('Male');
    this.query = this.query.match(this.category)[0];
}