【发布时间】:2019-11-11 15:09:14
【问题描述】:
我正在研究 vanilla js,因为我根本不允许使用 jQuery,所以我几乎是初学者,所以我想要一个指南,我正在尝试从 JSON 文件中获取电子邮件地址我'已经尝试做一个循环,但它永远不会到达属性电子邮件并显示它。
我已经试过了:
我搜索输入文本并获取值并将其存储在 textValue 中,然后尝试使用 for-loop 查找该值。
var textValue = document.getElementById("email").value;
for(var i = 0; i < localStorage.getItem(jsondata.data.length); i++)
{
if(jsondata[i].email == textValue)
{
console.log(jsondata[i].email)
}
}
};
这是 JSON 的外观:
{
"data": [
{
"email": "nicobes@gmail.com",
"name": "Nickole Beatrice Smith",
"address": "398 Pleasant Pine Cir. Harrington, DE 19123",
"age": 45,
"notes": "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, ",
"phoneNumbers": [
{
"phone": "(302) 792-8434"
},
{
"phone": "(302) 792-1134"
},
{
"phone": "(302) 792-2234"
},
{
"phone": "(302) 792-3334"
}
],
"relatives": [
{
"name": "Susan M Smith"
},
{
"name": "Malcolm W Smith"
},
{}
]
}
【问题讨论】:
标签: javascript html json