With the omit()
method of Underscore.js, we can return an object's properties by omitting some specified ones. We only need to specify the properties we want to omit.
_.omit(object, *property)
object
: This is the object we want to return but omit some of its properties.
*property
: This is a property we want to omit. It could be one or more.
The value returned is an object with some of its properties omitted.
// require underscoreconst _ = require("underscore")// create some objectslet obj1 = {one: 1, two: 2, three: 3, four: 4}let obj2 = {name: "nodejs", package: "underscore", tag: "_"}let obj3 = {a: "Apple", b: "Banana"}let obj4 = {M: "Monday", T: "Tuesday", W: "Wednesday"}// get inverted objectsconsole.log(_.omit(obj1, "one"))console.log(_.omit(obj2, "package", "tag"))console.log(_.omit(obj3, "a", "b"))console.log(_.omit(obj4, "T", "M"))
underscore
package.omit()
method to omit some properties of the objects we created. Then, we print the results to the console.