You can use the _.size
function from the Underscore.js library to get the number of elements in an array or an object. Here is an example:
index.tsx207 chars8 lines
In the first example, we have an array of numbers and we use _.size
to get the number of elements in the array, which is 5.
In the second example, we have an object representing a person, and we use _.size
to get the number of properties in the object, which is 3.
As you can see, _.size
is a useful function to have when working with arrays and objects in JavaScript.
gistlibby LogSnag