[英]Split array object by string by @ sign
我有流动的数组对象
let old_array = {
"valone": "facebook",
"notification": "new message! @user1@example.com @user2@example.com"
}
我想打破让所有具有@符号的用户进入像下面这样的新数组
let new_array = {"user1@example.com", "user2@example.com"}
任何想法如何做到这一点,我有用户数组拆分即时消息只能用@符号获取电子邮件。
let new_array = old_array .split("@");
尝试这个:
let old_array = { "valone": "facebook", "notification": "new message! @user1@example.com @user2@example.com" } const result = old_array.notification.match(/(?<=@)(\\w*@\\w*.\\w*)/g); console.log(result);
您必须在old_array
拆分字符串。 尝试这个:
let old_array = { "valone": "facebook", "notification": "new message! @user1@example.com @user2@example.com" } let notification = old_array["notification"]; //Get notification-property let email_string = notification.substring(notification.indexOf("@")).trim(); //Get rid of the message let email_array = email_string.split(" "); //Split by " " to get the different emails console.log(email_array);
您可以通过搜索@
然后加上非空格来匹配电子邮件。
var string = 'new message! @user1@example.com @user2@example.com', emails = string.match(/@\\S+/g); console.log(emails);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.