I have JSON Data and i need last obj value from same type obj values.
I want to Get last index of Foo value Bar.
I know how to get last index of json array.
var data = [{
"foo": "bar"
},
{
"foo": "bar-1"
},
{
"foo": "bar-2"
},
{
"foo": "bar-1"
},
{
"foo": "bar"
},
{
"foo": "bar-1"
},
]
$.each(data, function(key, val) {
if (val.foo == "bar") {
console.log(key);
}
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>