Let’s say the following is our object −
var apiJSONObject =
[
{subjectName:"MySQL"},
{subjectName:"Java"},
{subjectName:"JavaScript"},
{subjectName:"MongoDB"}
]Let’s check for existence of a value “JavaScript” −
Example
var apiJSONObject =
[
{subjectName:"MySQL"},
{subjectName:"Java"},
{subjectName:"JavaScript"},
{subjectName:"MongoDB"}
]
for(var i=0;i<apiJSONObject.length;i++){
if(apiJSONObject[i].subjectName=="JavaScript"){
console.log("The search found in JSON Object");
break;
}
}To run the above program, you need to use the following command −
node fileName.js.
Here, my file name is demo117.js.
Output
This will produce the following output −
PS C:\Users\Amit\JavaScript-code> node demo117.js The search found in JSON Object