如何从 arraylist 映射特定 属性

How mapping specific property from arraylist

我正在寻找一种方法来从我的 postList 列表中获取所有电子邮件 属性 以过滤授权的最大字符数,问题是我真的不知道如何从 postList 映射电子邮件 属性.. .

const postList = [
 {"postId": 1, "id": 1, "email": "Eliseo@gardner.biz"},
 {"postId": 1, "id": 2, "email": "Jayne_Kuhic@sydney.com"},
 {"postId": 1, "id": 3, "email": "Nikita@garfield.biz"},
 {"postId": 1, "id": 4, "email": "Lew@alysha.tv"},
]

const onlyEmailValid = []

for (let i = 0; i < postList.length; i++) {
   if(postList.email.value.length > max_chars) {
     console.log("email : " + postList.email + " has too long");
       continue
     }
      
     onlyEmailValid.push(postList[i]);
}
console.log(clearJobList);

const postList = [
 {"postId": 1, "id": 1, "email": "Eliseo@gardner.biz"},
 {"postId": 1, "id": 2, "email": "Jayne_Kuhic@sydney.com"},
 {"postId": 1, "id": 3, "email": "Nikita@garfield.biz"},
 {"postId": 1, "id": 4, "email": "Lew@alysha.tv"},
]

const onlyEmailValid = []
const max_chars = 15 //example
for (let i = 0; i < postList.length; i++) {
   if(postList[i].email.length > max_chars) {
     console.log("email : " + postList[i].email + " has too long");
       continue
     }
      
     onlyEmailValid.push(postList[i]);
}
console.log(onlyEmailValid);

你好尝试使用filter方法

const postList = [
 {"postId": 1, "id": 1, "email": "Eliseo@gardner.biz"},
 {"postId": 1, "id": 2, "email": "Jayne_Kuhic@sydney.com"},
 {"postId": 1, "id": 3, "email": "Nikita@garfield.biz"},
 {"postId": 1, "id": 4, "email": "Lew@alysha.tv"},
]

const onlyEmailValid = []
const max_chars = 13
postList.filter(item=>{
    (item.email.length > max_chars) ? console.log("email : " + item.email + " has too long") : onlyEmailValid.push(item);
})

console.log(onlyEmailValid);