lodash object methods and beyond

Lodash Object methods start with assign, and end with valuesIn but that is of course only the lodash methods that work with just about any object in javaScript. There are also the lodash array methods, and in JavaScript an array is just a certain kind of object. There are also collection methods that designed to work with plain old objects by themselves, array like objects, and objects that are javaScipt arrays. In this post I hope to give a general overview of lodash object methods, and also of objects in general in javaScript.

1 - lodash object methods

In lodash there are a number of methods that are considered object methods. These kinds of methods are intended to be used with just about any kind of object in javaScript, not just a certain kind of object that was created with a specific constructor function likes Arrays. There are a few methods that bring about functionality that still as of this writing is not part of core javaScript at all, however many others are now part of the javaScript spec.

For example in lodash there is the _.assign method

1
2
3
4
5
6
7
8
let _ = require('lodash');
let obj = {n:42,a:{b:12}};
let obj2 = _.assign({},obj);
obj.a.b = 13;
console.log(obj2.a.b);

However there is also the native Object.assign methods as well now.

1.2 - lodash array object methods

In lodash there are a number of methods that are intended to be used with arrays. Arrays are a kind of object in javaScript but they are a special kind of object that is formated in a way in which each key is a numbered index, and there is a length property that reflects the number of elements in the array. In addition Arrays are created using the Array constructor or array literal syntax and as such they inherit a bunch of prototype methods, some of which a similar if not identical to many lodash array methods.

1.1 - lodash collection object methods

In lodash there are a number of methods that are considered collection methods. These methods will work with javaScript objects that are created with the Array constructor. However they will also work just fine with objects that are not created with the array constructor as well, even if they are not array like. Collection methods can be though of as lodash object methods as well, but they are intended to be used with objects that have a collection like nature.

2 - Some plain lodash object methods of interest

So maybe all lodash Array, collection, and object methods are all technically object methods. However in this section, I will be covering some lodash object methods that are still of interest as of this writing. What I mean by that is that many of the lodash object methods now have native counterparts backed into core javaScript by itself. There is still the question of supporting older browsers, and some of the methods do behave a little differently, but for the most part there are only a few object methods that are still of interest when it comes to only being concerned about modern browsers.