What is lodash.has?
The lodash.has package is a method from the Lodash library, which is a popular JavaScript utility library. This specific method is used to check if a path exists as a property in a given object, which can be deeply nested. It helps in safely checking for the existence of a property without manually traversing the properties and handling errors.
Check existence of a property
This feature allows you to check whether a specific path exists within an object. It returns true if the path exists, otherwise false. This is useful for avoiding errors when accessing deeply nested properties.
const _ = require('lodash.has');
const object = { 'a': { 'b': { 'c': 3 } } };
console.log(_.has(object, 'a.b.c')); // => true
console.log(_.has(object, 'a.b.c.d')); // => false