0

Im trying to get a function returned value out from it.

function startFilter(callback) {
    $.getJSON('services/hoteljson.php', callback);
}
var data =  startFilter(function(json) {
    json= jQuery.grep(json, function(element, index){
        var productNameSearch = new RegExp('Hot' , "gi");
        return element.prodname.match(productNameSearch);
    });
    return json;
});

I've tired few options but nothing seems to be wokring

i wanted to use data anywhere i wish.

what will be the best method to do so?

Review:

The duplicate question doesn't give the answer what i seek, just some showoff stuff.

Fahid Mohammad
  • 910
  • 3
  • 17
  • 47
  • `data` looks the most outside. So should work. Need to test otherwise, but your code is too specific, so most people can't test. –  Jun 25 '14 at 05:33
  • this should have been marked as *Unclear what you are asking* instead. – King King Jun 25 '14 at 06:31
  • data is never set to json because startFilter immediately returns undefined because getJSON is an aynchronous function. Your best bet is to call the function that should use data from within the callback with json as argument – Ferdi265 Jun 25 '14 at 06:58

0 Answers0