Lodash.js – findLastIndex() function

A simple Lodash.js example of the findLastIndex() function, we will return the index of the element we are seeking for, but iterating from the end to the beggining of the provided collection.
<!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 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 = [{'quantity':152, 'weight':42},
                      {'quantity':122, 'weight':32},
                      {'quantity':15, 'weight':2},
                      {'quantity':52, 'weight':25}];

  firstDiv.innerHTML = "Having the array of objects, we will find the index of the object {'quantity':15, 'weight':2} in the provided array (iterating from the end to the beggining)...";

    var result = _.findLastIndex(firstValue, {'quantity':15, 'weight':2});

  secondDiv.innerHTML = "...and we will get: " + result;

</script>
</body>

</html>

Responses

0 Replies