
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Check Whether a Value Exists in JSON Object
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
Advertisements