Zantinger Zantinger - 1 year ago 83
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)

Answer Source

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))
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download