`_.has` function on object using JavaScript Library underscore.js ( #shorts )

1 year ago
1

Hi Friends,

`_.has` function on object using JavaScript Library underscore.js

`_.has` is a utility function in Underscore.js library that allows us to check if an object contains/has a specific property regardless of the property's value.

In below example, we have an object person that has a person's details. We use _.has to check if the person object has the properties "name" and "phone". The first call to _.has returns true because the person object has the "name" property. The second call returns false because the person object does not have the "phone" property.

Note: _.has can be useful when we want to conditionally access or manipulate a property only if it exists in the object.

// syntax
_.has(object, key)

// example
var person = { name: "Annie", age: 25, city: "New York" };

console.log(_.has(person, "name"));
// true

console.log(_.has(person, "phone"));
// false

#javascript #under #score #underscore #underscorejs #has #hastag #underscoreget #getfunction #unique #object #array #string #nodejs #javascriptinterview #method #js #jquery #function #shorts #viral #popular #latest #new #coders #development #code #dev #interview #php #trend #trending #answer #laravel #youtube #instagram #socialmedia #education #edit #how #india #knowledge #quiz #reels #short #subscribe #share #update #video #web #webdeveloper #website #webdesign #ytshorts #youtuber #princecheema_official @princecheema_official

Loading comments...