get value from nested each() loop

by Sethu raman

JavaScript

var my_array = [{"check": "tom", "nested_array": [{"nested_array_2": ["1", "2"], "name": "tom", "image": "one.jpg"}, {"nested_array_2": ["1", "2"], "name": "bob", "image": "two.jpg"}]}];

var check = my_array[0].check;

var desired_value = "hello";

$.each(my_array, function (obj, v) {
$.each(v.nested_array, function (i, value) {
if (value.name == check) {
desired_value = value.image;
alert(desired_value);  // this returns `one.jpg`, the variable has been updated.  
}
});
});

alert(desired_value); // this alerts 'hello',  the variable has not been updated.