Lodash.js – intersection() function

A simple Lodash.js example of the intersection() function, which returns an array of values shared between the examined arrays.
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8"/>
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0">
    <meta name="description" content="Tizen Angular.js example"/>
    <title>Tizen lodash.js example</title>
    <script src="js/lodash.min.js"></script>
</head>
<body>
<div id="first">
</div>
<br>
<div id="second">
</div>

<script>

    var firstDiv = document.getElementById('first');
    var secondDiv = document.getElementById('second');

    var firstValue = [[1, 0, 5, 2],[3, 24, 5, 2],[2, 5, 18, 12]];

  firstDiv.innerHTML = "Having the arrays: " + firstValue[0] + " and " + firstValue[1] + " and " + firstValue[2] + " using the lodash intersection function, we will get an array of shared values between those arrays...";

    var result = _.intersection(firstValue[0], firstValue[1], firstValue[2]);

  secondDiv.innerHTML = "...so we get: " + result;

</script>
</body>

</html>

Responses

0 Replies