Lodash.js – keysIn() function

A simple Lodash.js example of the keysIn() function, which creates an arrays of property names, based on the provided object. It also takes into account the inherited properties.
<!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');

    function SampleObject() {

        this.first = 25;
        this.second = 35;
        this.third = 50;

    }

    SampleObject.prototype.fourth = 75;

    var myObject = new SampleObject();

    firstDiv.innerHTML = "Having an object with data:<br><br>";
    firstDiv.innerHTML += JSON.stringify(myObject);

    secondDiv.innerHTML = "...we will create an array of properties of the object.. and we get:<br><br>";

    var result = _.keysIn(myObject);

    secondDiv.innerHTML += JSON.stringify(result);

</script>
</body>

</html>

Responses

0 Replies