Lodash.js – forEachRight() function

A simple Lodash.js example of the forEachRight() function, which iterates through every key in a given collection from the end to the beggining.
<!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 = {'price': 1, 'weight': 0, 'occurence': 5, 'time': 4};

  firstDiv.innerHTML = "Having the object: " + firstValue + " we will iterate through all keys and values of it from the end to the beggining...";

    var result = _.forEachRight(firstValue, function(val, key) {

      document.write("<br>key: " + key + ", value: " + val);

    });

</script>
</body>

</html>

Responses

0 Replies