javascript - variable(search) not defined error -
function sort(type) { $("#parentdiv").empty(); $.getjson("raw_data.json", ({ search })); function sear(a, b) { return (a[search.type] < b[search.type]) ? -1 : (a[search.type] > b[search.type]) ? 1 : 0; }; }
my raw_data.json
here.
though i've declared search. occuring error:
search not defined.
function sort(type) { $("#parentdiv").empty(); $.getjson("raw_data.json", ({ search }) => { search.sort(function(a,b){ if(a[type]<b[type]){return -1;} else if(a[type]>b[type]){ return 1; } else { return 0; } }); console.log(`sorted by: ${type}`); console.log("movies displayed!!"); var i; ... code