Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

lodash check object properties has values

I have object with several properties, says it's something like this

{ a: "", b: undefined }

in jsx is there any one line solution I can check whether that object's property is not empty or has value or not? If array there's a isEmpty method.

I tried this

const somethingKeyIsnotEmpty = Object.keys((props.something, key, val) => {
        return val[key] !== '' || val[key] !== undefined
})
like image 462
Celdric Kang Avatar asked Jul 07 '17 03:07

Celdric Kang


People also ask

How do you check if the property exists in an object Lodash?

Lodash _.has() Method The _.has() method is used to check whether the path is a direct property of object or not. It returns true if path exists, else it returns false.

How do I check if a Lodash object is empty?

The Lodash _. isEmpty() Method Checks if the value is an empty object, collection, map, or set. Objects are considered empty if they have no own enumerable string keyed properties. Collections are considered empty if they have a 0 length.

How do you check if an object is empty?

keys(object) method: The required object could be passed to the Object. keys(object) method which will return the keys in the object. The length property is used to the result to check the number of keys. If the length property returns 0 keys, it means that the object is empty.

Is Lodash still needed 2022?

But Sometimes You Do Need Lodash Not every Lodash utility is available in Vanilla JavaScript. You can't deep clone an object, for example. That's why these libraries are far from obsolete. But if you're loading the entire library just to use a couple of methods, that's not the best way to use the library.


1 Answers

In lodash, you can use _.some

_.some(props.something, _.isEmpty)
like image 128
Mukesh Soni Avatar answered Oct 07 '22 12:10

Mukesh Soni