Can you teach me how to locate a json object in JavaScript?
Here is a sample Json:
{
"Employees" : [
{
"userId":"rirani",
"jobTitleName":"Developer",
"preferredFullName":"Romin Irani",
"employeeCode":"E1",
"region":"CA",
"phoneNumber":"408-1234567",
"emailAddress":"<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="dfadb0b2b6b1f1b4f1b6adbeb1b69fb8b2beb6b3f1bcb0b2">[email protected]</a>"
},
{
"userId":"nirani",
"jobTitleName":"Developer",
"preferredFullName":"Neil Irani",
"employeeCode":"E2",
"region":"CA",
"phoneNumber":"408-1111111",
"emailAddress":"<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="caa4afa3a6b8a3b8aba4a38aada7aba3a6e4a9a5a7">[email protected]</a>"
}
]
}
In the above JSON, I want to search for a specific userId based on employeeCode, emailAddress, and PhoneNumber. Currently, my approach is as follows:
for(var i=0; i<json.length;i++){
if((employeeCode==code)&&(emailAddress ==email)&&(PhoneNumber==phone)){
//here i am getting userId
}
}
I'm not sure if this method is correct. It works fine for small sets of data, but what should I do if I have a large amount of data to search through?