javascript - 通过 @ 符号按字符串拆分数组对象

标签 javascript arrays node.js

我有流动的数组对象

let old_array = {
 "valone":  "facebook",
 "notification": "new message! @<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="9eebedfbecafdefbe6fff3eef2fbb0fdf1f3" rel="noreferrer noopener nofollow">[email protected]</a> @<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="b4c1c7d1c686f4d1ccd5d9c4d8d19ad7dbd9" rel="noreferrer noopener nofollow">[email protected]</a>"
}

我想将所有带有 @ 符号的用户分解到新数组中,如下所示

let new_array = {"<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="b8cdcbddca89f8ddc0d9d5c8d4dd96dbd7d5" rel="noreferrer noopener nofollow">[email protected]</a>", "<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="47323422357507223f262a372b226924282a" rel="noreferrer noopener nofollow">[email protected]</a>"}

知道如何做到这一点,我有用户数组拆分,我只能收到带有 @ 符号的电子邮件。

let new_array = old_array .split("@");

最佳答案

试试这个:

let old_array = {
 "valone":  "facebook",
 "notification": "new message! @<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="8df8fee8ffbccde8f5ece0fde1e8a3eee2e0" rel="noreferrer noopener nofollow">[email protected]</a> @<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="a8dddbcdda9ae8cdd0c9c5d8c4cd86cbc7c5" rel="noreferrer noopener nofollow">[email protected]</a>"
}

const result =  old_array.notification.match(/(?<=@)(\w*@\w*.\w*)/g);

console.log(result);

关于javascript - 通过 @ 符号按字符串拆分数组对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57097331/

相关文章:

javascript - 从 C# 执行 JS 代码时出现异常 : Function expected

arrays - 如何循环遍历不同类型的类数组并快速打印它们的属性?

arrays - 计算乘积不能被 k 整除的子数组的个数

javascript - 在 MongoDB 中使用原生 ES6 Promise

javascript - this.functionName 的工作方式因事件监听器而异

javascript - 从javascript click()动态设置 anchor 文本

javascript - 在 <a> 元素中禁止点击输入

python - 将 Cython 中的 numpy 数组传递给需要动态分配数组的 C 函数

node.js - 在 Mac 上打开 Electron 应用程序时出现问题 - "the git command requires command line developer tools."

node.js 通过代理的 Https 请求失败