question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Omit by function?

See original GitHub issue

Lodash has a neat way to remove all null and undefined keys from an obj: _.omit(obj, v => v == null). Currently omit() only accepts strings - can y’all make it optionally take a function parameter?

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

5reactions
Bradcompcommented, Feb 8, 2017

R.filter and R.reject will work on objects in the way you envision they would: https://goo.gl/Od3t5g

const o = {a: null, b: 'yo', c: 'hello there', d: 12}

filter(is(String), o)  //{"b": "yo", "c": "hello there"}
reject(isNil, o)       //{"b": "yo", "c": "hello there", "d": 12}
1reaction
phhucommented, Mar 29, 2020

See also omitBy function in ramda adjunct: https://char0n.github.io/ramda-adjunct/2.26.0/RA.html#.omitBy

const isLowerCase = (val, key) => key.toLowerCase() === key;
RA.omitBy(isLowerCase, {a: 1, b: 2, A: 3, B: 4}); //=> {A: 3, B: 4}
Read more comments on GitHub >

github_iconTop Results From Across the Web

Underscore.js | _.omit() Function - GeeksforGeeks
The _.omit() function is used to return a copy of the object that filtered to omit the blacklisted keys. Syntax: _.omit(object, *keys).
Read more >
What is the omit() function in Underscore.js? - Educative.io
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...
Read more >
Omit object properties based on function - 30 seconds of code
Omits the key-value pairs corresponding to the keys of the object for which the given function returns falsy. Use Object. keys() and Array....
Read more >
Underscore.JS - omit method - Tutorialspoint
omit (student, 'name', 'age'); console.log(student1); // Example 2: use omit to exclude age and id using function ...
Read more >
How to omit specific properties from an object in JavaScript
function omit (keys, obj) { if (!keys.length) return obj const { [keys.pop()]: omitted, ...rest } = obj; return omit(keys, rest); }.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found