我正在使用这个库在字符串中查找电子邮件地址。 https://github.com/sindresorhus/get-emails
我正在努力获取结果。
getEmails(text); //=> Set {'sindresorhus@gmail.com', 'unicorn@rainbow.cake'}
typeof getEmails(text); // 'object'
如何访问此对象中的第一个电子邮件地址?
最佳答案
看起来 getEmails
实际上返回一个 ES6 Set
对象,而不是一个数组:
获取第一封电子邮件:
// Option 1 (ugly but efficient)
let first = getEmails(text).values().next().value
// Option 2 (pretty but inefficient)
first = [...getEmails(text)][0]
console.log(first)
遍历所有电子邮件:
for (let email of getEmails(text)) {
console.log(email)
}
关于javascript - 访问 ES6 Set 对象中的字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42587565/