Skip to content
Advertisement

how to return boolean value based on condition check in array object javascript

I have object array obj1, obj2,

if the name of object cannot have All key name return true

if the name of object can have only one All key name and other object return false

if the name of object can have only one All key name and no other object return true

if the name of object has too many key name All return false

based on above conditions how to do in javascript.

JavaScript

Advertisement

Answer

You can check if the array has any objects with name = "All".

Then, return true if

  • The array has name = "All" object and the array’s length is 1
  • or the array doesn’t have name = "All"
JavaScript

Here’s a snippet:

JavaScript
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement