- 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 - intersection method
Syntax
_.intersection(*arrays)
intersection method returns a intersection of passed arrays i.e. an array of common 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: intersection of list1 and list2 result = _.intersection(list1, list2); console.log(result) //Example 2: intersection of list1, list2, list3 result = _.intersection(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 ] [ 1, 2 ]
underscorejs_processing_array.htm
Advertisements