O'Reilly logo

Learning Underscore.js by Alex Pop

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Objects

Underscore has a series of dedicated functions targeting objects, which extends the features provided for collections.

Underscore keys

We will revisit the propertyFormatter related examples to showcase some of the object-related features, and we will start with the function _.keys(object). This function will extract an array containing the names of all enumerable properties from the object parameter. It ignores any properties that are inherited, and if you want to include those as well you need to use the _.allKeys(object) function instead.

Going back to the original propertyFormatter.extractPropertiesForDisplayAsArray() function introduced in Chapter 2, Using Underscore.js with Collections, we can now change it to use _.keys(object) to ensure ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required