- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- 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
- Related Articles
- How to check whether an object exists in JavaScript?
- Check whether property exists in object or class with PHP
- Check whether given key already exists in a dictionary in Python
- Check if a particular value exists in Java LinkedHashMap
- Check if a particular value exists in Java TreeSet
- How do I check whether a file exists using Python?
- C# Program to check whether a directory exists or not
- Java Program to check whether a file exists or not
- How can I check whether a field exists or not in MongoDB?
- How to check whether a data frame exists or not in R?
- How to check whether a column exists in an R data frame?
- Check whether a string is valid JSON or not in Python
- Check if value exists for a field in a MongoDB document?
- Check if a value exists in a column in a MySQL table?
- Finding the smallest value in a JSON object in JavaScript

Advertisements