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

1 year ago
1

Hi Friends,

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

`_.pick` is a utility function in Underscore.js library that allows you to create a new object by exclude certain properties from an object without those properties.

In below example, we have an object person that represents a person's details. We use _.omit to exclude the age and profession properties from the person object. The variable omittedProps is a new object that contains all properties from the person object except age and profession.

Note: You can pass multiple property keys as arguments to _.omit, and it will create a new object without those properties if they exist in the source object.

// syntax
_.omit(object, *keys)

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

var omittedProps = _.omit(person, "age", "city");

console.log(omittedProps);
// { name: "Alice", profession: "Engineer"}

#javascript #under #score #underscore #underscorejs #omit #underscoreomit #omitfunction #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...