Lodash.js – at() function

A simple Lodash.js example of the at() function, which takes from an array indexes with values specified in the second parameter of the function.
<!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 = [12, 42, 56, 23, 12, 34, 98];

  firstDiv.innerHTML = "Having the array: " + firstValue + " we will take to a new array values AT indexes 1, 3 and 6...";

    var result = _.at(firstValue, [1,3,6]);

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

</script>
</body>

</html>

Responses

0 Replies