Skip to content
Advertisement

How to get the length of an object after checking it is an array in Javascript

I have an array of objects, there is one field in each object could be boolean or a string of array, for instance

JavaScript

I would like to filter out the objects that have selected either not empty or true. The result would be:

JavaScript

Here is my code:

JavaScript

But objects with selected is empty array won’t get filter out. I got a typescript error

JavaScript

Can anyone help?

Advertisement

Answer

You can use the filter method on the myObjects array

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