Lodash.js – where() function
A simple Lodash.js example of the where() function, which compares (deep comparison) elements in order to check if they are in the collection and returns the ones that match.
<!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 = [{'name':'Bart', 'knowsJavaScript':true, 'age':31},
{'name':'Slav', 'knowsJavaScript':false, 'age':30},
{'name':'Bixby', 'knowsJavaScript':false, 'age':30},
{'name':'Michael', 'knowsJavaScript':true, 'age':30},
{'name':'Michael', 'knowsJavaScript':true, 'age':37}];
firstDiv.innerHTML = "Having an object collection:<br><br>";
firstDiv.innerHTML += JSON.stringify(firstValue);
var result = _.where(firstValue, {'name':'Michael', 'knowsJavaScript':true});
secondDiv.innerHTML = "We compare (deep comparison) elements in order to check if they are in the collection...<br><br>";
secondDiv.innerHTML += "...and we get: " + JSON.stringify(result) + "<br>";
</script>
</body>
</html>