- Underscore.JS Tutorial
- Underscore.JS - Home
- Underscore.JS - Overview
- Underscore.JS - Environment Setup
- Underscore.JS - Iterating Collection
- Underscore.JS - Processing Collection
- Underscore.JS - Iterating Array
- Underscore.JS - Processing Array
- Underscore.JS - Functions
- Underscore.JS - Mapping Objects
- Underscore.JS - Updating Objects
- Underscore.JS - Comparing Objects
- Underscore.JS - Utilities
- Underscore.JS - Chaining
- Underscore.JS Useful Resources
- Underscore.JS - Quick Guide
- Underscore.JS - Useful Resources
- Underscore.JS - Discussion
Underscore.JS - union method
Syntax
_.union(*arrays)
union method returns a union of passed arrays i.e. a combined array of unique values from each array.
Example
var _ = require('underscore'); var list1 = [1, 2, 3, 4, 5, 6] var list2 = [1, 2, 3, 7] var list3 = [1, 2, 4, 5, 6, 7, 8] //Example 1: union of list1 and list2 result = _.union(list1, list2); console.log(result) //Example 2: union of list1, list2, list3 result = _.union(list1, list2, list3); console.log(result)
Save the above program in tester.js. Run the following command to execute this program.
Command
\>node tester.js
Output
[ 1, 2, 3, 4, 5, 6, 7 ] [ 1, 2, 3, 4, 5, 6, 7, 8 ]
underscorejs_processing_array.htm
Advertisements