Lodash.js – has() function
A simple Lodash.js example of the has() function, which checks if a value from the specified path exists.
<!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 = {'fruit':[20, {"grapes":20, 'bananas':45, 'chemicals':[1,2,3]}]};
var searchPath = 'fruit[1].chemicals[0]';
firstDiv.innerHTML = "Having an object with data:<br><br>";
firstDiv.innerHTML += JSON.stringify(firstValue);
secondDiv.innerHTML = "...we will check if a value specified by the provided path " + searchPath + " exists... and we get:<br><br>";
var result = _.has(firstValue, searchPath);
secondDiv.innerHTML += JSON.stringify(result);
</script>
</body>
</html>