Book Image

Learning Underscore.js

By : Alexandru Vasile Pop
Book Image

Learning Underscore.js

By: Alexandru Vasile Pop

Overview of this book

Table of Contents (14 chapters)
Learning Underscore.js
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Other collection-based functions


There are three more collection transformation functions that we will mention briefly here:

  • _.toArray(list) creates a native Array object from a collection.

  • _.shuffle(list) creates an array of randomized collection items using the Fisher-Yates shuffle algorithm.

  • _.sample(list, [n]) also creates an array of randomized collection items with an optional limit of n array items. If n is not specific, it returns one random item from the collection.

The last collection specific function for this chapter is _.invoke(list, methodName, *arguments) that will call method methodName for each collection item and will optionally pass an arguments list to the invoked method.