<!DOCTYPE html>
<html lang="en-US">
<body>
<h1>JSON findLastIndex</h1>
<p>Find the last index of the object with respect to the given name ('Danny').</p>
<button onclick="myFunction()">Click Me</button>
<script>
var data = [
{
"name": "Danny",
"age": 25
},
{
"name": "Mike",
"age": 25
},
{
"name": "Danny",
"age": 18
}
]
var myIndex = -1;
function myFunction(){
for(var i = 0; i < data.length; i++){
if (data[i].name == "Danny")
myIndex = i;
}
console.log(myIndex);
}
</script> </body>
</html>