Skip to content
Advertisement

How to get items from a list but only after a condition is met?

If I have a list

JavaScript

and I basically want to count the amount of items in the list but only start after the leading zeroes, how would I do that? Keep in mind that I want to count the zero in the middle of the list but not the ones at the beginning.

I’ve tried this:

JavaScript

But it didn’t get 4, which is the output I want as I want to include 2.0,3.0,0.0,2.0 only.

Advertisement

Answer

You can simply wrap your counter code in a conditional, with something like this:

JavaScript

item_count will now have the amount of items in the list without the starting 0.0s

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