I have a list with the following values:
const myList = [True, False, False]
With myList.length I get the value 3.
Now I want the length of the list with all False values.
How can I return the length with a condition?
I have a list with the following values:
const myList = [True, False, False]
With myList.length I get the value 3.
Now I want the length of the list with all False values.
How can I return the length with a condition?
const myList = [True, False, False].filter(el => el === false)
console.log(myList.length)
You can use Array.filter()
to do it
let len = myList.filter(i => !i).length
const myList1 = [true, false, false]
let len1 = myList1.filter(i => !i).length
console.log(len1)
const myList2 = ['True', 'False', 'False']
let len2 = myList2.map(i => i.toLowerCase() === 'true').filter(i => !i).length
console.log(len2)
You could count the values.
const
True = true,
False = false,
getCount = (array, value) => array.reduce((t, v) => t + (v === value), 0),
myList = [True, False, False];
console.log(getCount(myList, False));