How to Check if a Key Exists in a Object Node.js?

07-Oct-2022

.

Admin

How to Check if a Key Exists in a Object Node.js?

Hello Friends,

Today, how to check if a key exists in an object node.js is our main topic. if you want to see an example of check if a key exists in an object nodejs then you are in the right place. In this article, we will implement a check if a key exists in an object node js. you can see nodejs check if a key exists in an object. Let's get started with node js to check if a key exists in an object.

This example is to check if a key exists in an object nodejs. I will give a simple example of check if a key exists in an object using the if condition.

Let's start following example:

Example: 1


// create color object

var car = {

color: 'blue'

}

// check key exit or not

if ('color' in car) {

console.log('key exists!')

}else{

console.log('key not exists!')

}

Output:

key exists!

Example: 2

// create color object

var car = {

color: 'blue'

}

// check key exit or not

if ('number' in car) {

console.log('key exists!')

}else{

console.log('key not exists!')

}

Output:

key not exists!

I hope it can help you...

#Node JS