Skip to content

UnderscoreJS library

UnderscoreJS is a library with handy methods for working with collections, arrays and objects. BizzStream allows you to use UnderscoreJS methods.

Extensive documentation can be found on http://underscorejs.org/.

Example: for loop

// Loop in plain Javascript
var pizzas = ["Pizza Mozzarella", "Pizza Margaritha", "Pizza Funghi"];
for(var i = 0; i < pizzas.length; i++) {
  console.log('pizza: ' + pizzas[i]);
  // 0 "Pizza Mozzarella"
  // 1 "Pizza Margaritha"
  // 2 "Pizza Funghi"
}
// Loop in UnderscoreJS
var pizzas = ["Pizza Mozzarella", "Pizza Margaritha", "Pizza Funghi"];
_.each(pizzas, function(pizza, index, pizzas) {
  console.log('pizza: ' + pizza);
    // 0 "Pizza Mozzarella"
    // 1 "Pizza Margaritha"
    // 2 "Pizza Funghi"
});

Example: find the even numbers

// Using _.filter
var numbers = [1, 2, 3, 4, 5, 6];

evenTester = function (numbers) {
            return numbers % 2 === 0;
        };

console.log('Even numbers: ' + _.filter(numbers, evenTester));
// Even numbers: 2, 4, 6