Lodash.js – forIn() function
A simple Lodash.js example of the forIn() function, which iterates through the objects' keys and their values. It also enumerates 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 Persons() {
this.isActive = true;
this.propertiesNum = 5;
this.mainName = 'myObject';
}
Persons.prototype.isDisabled = false;
var persons = new Persons();
firstDiv.innerHTML = "Having an object with data objects:<br><br>";
firstDiv.innerHTML += JSON.stringify(persons);
secondDiv.innerHTML = "...we will list all the people... and we get:<br><br>";
var result = _.forIn(persons, function(value, key) {
secondDiv.innerHTML += "<b>key:</b> " + key + "<b>, value: </b>" + value + ",<br>";
});
</script>
</body>
</html>