如何映射arraylist的特定属性

发布于 2025-01-18 04:16:20 字数 1132 浏览 4 评论 0原文

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

const postList = [
 {"postId": 1, "id": 1, "email": "[email protected]"},
 {"postId": 1, "id": 2, "email": "[email protected]"},
 {"postId": 1, "id": 3, "email": "[email protected]"},
 {"postId": 1, "id": 4, "email": "[email protected]"},
]

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);

I m looking a way to get all email property from my postList list to filtering max chars authorized, the problme is i don't know really how mapping email property from postList...

const postList = [
 {"postId": 1, "id": 1, "email": "[email protected]"},
 {"postId": 1, "id": 2, "email": "[email protected]"},
 {"postId": 1, "id": 3, "email": "[email protected]"},
 {"postId": 1, "id": 4, "email": "[email protected]"},
]

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);

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

终止放荡 2025-01-25 04:16:20
const postList = [
 {"postId": 1, "id": 1, "email": "[email protected]"},
 {"postId": 1, "id": 2, "email": "[email protected]"},
 {"postId": 1, "id": 3, "email": "[email protected]"},
 {"postId": 1, "id": 4, "email": "[email protected]"},
]

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);

const postList = [
 {"postId": 1, "id": 1, "email": "[email protected]"},
 {"postId": 1, "id": 2, "email": "[email protected]"},
 {"postId": 1, "id": 3, "email": "[email protected]"},
 {"postId": 1, "id": 4, "email": "[email protected]"},
]

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);

千紇 2025-01-25 04:16:20

您好尝试使用 filter 方法

const postList = [
 {"postId": 1, "id": 1, "email": "[email protected]"},
 {"postId": 1, "id": 2, "email": "[email protected]"},
 {"postId": 1, "id": 3, "email": "[email protected]"},
 {"postId": 1, "id": 4, "email": "[email protected]"},
]

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);

Hello try to use filter method

const postList = [
 {"postId": 1, "id": 1, "email": "[email protected]"},
 {"postId": 1, "id": 2, "email": "[email protected]"},
 {"postId": 1, "id": 3, "email": "[email protected]"},
 {"postId": 1, "id": 4, "email": "[email protected]"},
]

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);

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文