Lodash.js – size() function

A simple Lodash.js example of the size() function, we will return the size of the provided collection, object, string, etc.
<!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 = [4,5,10,6,4,20,12];

  firstDiv.innerHTML = "Having the array: " + firstValue + " with the size function we will...";

    var result = _.size(firstValue);

  secondDiv.innerHTML = "...get: " + result + " elements of the provided collection.";

</script>
</body>

</html>

Responses

0 Replies