Method to check if array element contains a false value in JavaScript?

JavascriptWeb DevelopmentObject Oriented Programming

To check if array element contains a false value, you can use the Object.values() in JavaScript. Following is the code −

Example

const details = [
   {
      customerDetails:
      [
         {
            isMarried: true
         },
         {
            isMarried: true
         }
      ]
   },
   {
      customerDetails:
   [
      {
            isMarried: true
         },
         {
         isMarried: true
         }
      ]
   }
]
const isNotMarried = Object.values(details)
.some(({customerDetails})=>customerDetails.some(({isMarried})=>!isMarrie
d));
console.log(isNotMarried);

To run the above program, you need to use the following command −

node fileName.js.

Here, my file name is demo75.js.

Output

This will produce the following output −

PS C:\Users\Amit\JavaScript-code> node demo75.js
false
raja
Published on 07-Sep-2020 07:47:16
Advertisements