lodash omit method for omitting properties from an object
The lodash omit method can be used to create a new object by omitting properties from an existing object that is give as the first argument. So then the lodash omit method is like the lodash pick method only it creates a new object by omitting properties that are not wanted rather than picking properties that are wanted.
1 - lodash omit basic example
For a Basic example of the lodash omit method I have an example here where I use the lodash omit method to create a new object from an object that has and z,y,z, and index values. The new Object just has an x, and y values because I use the lodash omit method to omit all the other properties by giving an array of property names that I do not want as the second argument when using the method.
1.1 - The lodash pick method can also be used to create a new object but by picking not omiting
So there is also the lodash pick method that works more or less the same way but by giving an array or properties that are to be picked for the new object from the given object rather than omitting properties.
2 - Using lodash map, some, remove, and fromPairs for a way more complex way of doing something fairly simple
So there are many other lodash methods that could also be used to create a new object from and object like this right? Well yes but sometimes I just end up making something far more complicated then it needs to be when doing that. For this example I was able to do the same thing but I ended up using lodash map to create an array of false values for properties that will be omitted and key value pairs for properties that will remain using the lodash some method to do file if that is the case or not. I then used the lodash remove method to remove the false index values from the array and have a clean set of key value pairs. Then once I have a set of key value pairs I can then use the lodash from pairs method to create the new object.
So then methods like the lodash omit methods can help keep me from making far more complex solutions like this for such a simple task right.
This way of making an omit method should work okay on most browsers as the array some method works on versions of ie that are as old as ie 9, and the object keys method also works on a wide range of browsers also. I could make another set of methods that would work on even older browser of need be but you get the idea. The lodash omit methods helps out a little because writing something like this over and over again when and where I need it can end up being a little time consuming.