我有這個陣列
let registers = [Register, Register, Register];
和
Register {name: 'Ray', email: '[email protected]', password: '1234'}
Register {name: 'Carl', email: '[email protected]', password: '4321'}
Register {name: 'Lina', email: '[email protected]', password: '5678'}
如何使用將@gmail.com 作為電子郵件的物件獲取新陣列?
uj5u.com熱心網友回復:
您可以在此處使用
const data = [
{ name: "Ray", email: "[email protected]", password: "1234" },
{ name: "Carl", email: "[email protected]", password: "4321" },
{ name: "Lina", email: "[email protected]", password: "5678" },
];
const output = data.filter((o) => o.email.match(/@gmail\.com$/));
console.log(output);
uj5u.com熱心網友回復:
Array.filter與 一起使用String.includes。
Array.filter用一些條件過濾原始陣列,其中String.includes提供條件,電子郵件包含一個字串@gmail.com
const data = [{ name: 'Ray', email: '[email protected]', password: '1234' },
{ name: 'Carl', email: '[email protected]', password: '4321' },
{ name: 'Lina', email: '[email protected]', password: '5678' }];
const output = data.filter(node => node.email.includes('@gmail.com'));;
console.log(output);
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/315791.html
標籤:javascript 数组 目的
上一篇:JavaScript:將陣列轉換為沒有鍵或字串的物件
下一篇:僅從物件陣列中回傳值
