使用 JavaScript 搜索 JSON 中的字符
[
{"lastName":"Noyce","gender":"Male","patientID":19389,"firstName":"Scott","age":"53Y,"},
{"lastName":"noyce724","gender":"Male","patientID":24607,"firstName":"rita","age":"0Y,"}
]
将我的输入与 JSON 进行比较。
for (var i = 0; i < recentPatientsList.length; ++i) {
if (searchBarInput === recentPatientsList[i].lastName) {
alert("Found at index " + i);
}
}
这样我就可以查看我的输入是否与 JSON 匹配。我如何获得姓氏以“N”开头或给定输入的数据的结果。
[
{"lastName":"Noyce","gender":"Male","patientID":19389,"firstName":"Scott","age":"53Y,"},
{"lastName":"noyce724","gender":"Male","patientID":24607,"firstName":"rita","age":"0Y,"}
]
Comparing my input with the JSON.
for (var i = 0; i < recentPatientsList.length; ++i) {
if (searchBarInput === recentPatientsList[i].lastName) {
alert("Found at index " + i);
}
}
With this i am able to see whether i match my input with the JSON. How can i get results of data whose last name starts with 'N' or given input.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
假设您 searchBarInput 等于
"n"
,试试这个:Assuming you searchBarInput is equal to
"n"
, Try this: