【发布时间】:2017-02-11 07:11:02
【问题描述】:
假设我有一系列推文:
var arr = ['@userone Hey man, whats popping', 'Shoutout to @usertwo haha']
我将如何摆脱提及并仅包含消息?比如:
var newArr = ['Hey man, whats popping', 'Shoutout to haha']
这是我能想到的
if (tweet.includes('@')) {
var atIndex = tweet.indexOf('@');
var spaceIndex = // index of the nearest space after @
var strToReplace = tweet.substring(atIndex, spaceIndex);
tweet = tweet.replace(strToReplace, '');
}
请帮忙。
【问题讨论】:
标签: javascript