Zantinger Zantinger - 7 months ago 54
Javascript Question

validate the correct types of a collection with lodash

I'm a little bit confusing about how to check a collection(object) with lodash _.some() function.

var x = {prop1: 800, prop2: 800, prop3: 'test'};

_.some(x, i => _.isNaN(i))

_.some(x, _.isNaN)


Now that you want to know if all of the properties are numbers, you can use this:

!_.some(x, i=> !_.isNumber(i))

I don't know about the perforamance differences of _.some and _.every but you could of course also use:

_.every(x, i=> _.isNumber(i))