Why cant I filter my javascript/jquery object -


i have javascript object array looks this:

[ {"fname":"tim", "lname":"thompson", "user_id": "2", "route_id": "3", "route_day": "wed"}, {"fname":"john", "lname":"wilson", "user_id": "3", "route_id": "3", "route_day": "wed"}, {"fname":"george", "lname":"lane", "user_id": "5", "route_id": "2", "route_day": "mon"} ] 

i tried filter out results using filter function

function filtercustomerdata(route,day) {      var jsoncustdata = json.parse(localstorage.getitem("db"));       console.dir(jsoncustdata); // object array 300+ objects     console.log( "route is: " + route + " day is: " + day);// route is: 3 day is: wed      var routes = jsoncustdata.filter(function(ele, ind,arr){         return ele.route_id == route && ele.route_day == day;     });      console.dir(routes); // array[0]       fillcustomerdata(routes); } 

but everytime empty array. know must doing wrong, can't figure out what.

edit: again sorry mistake, entered full function time.

  1. use == instead of =
  2. use route_day instead of route_day

var objarr = [  {"fname":"tim", "lname":"thompson", "user_id": "2", "route_id": "3", "route_day": "wed"},  {"fname":"john", "lname":"wilson", "user_id": "3", "route_id": "3", "route_day": "wed"},  {"fname":"george", "lname":"lane", "user_id": "5", "route_id": "2", "route_day": "mon"}  ];    var newobj = objarr.filter(function(ele, ind, arr){    console.log(ele);      return ele.route_id == "3" && ele.route_day == "wed";  });    console.log(newobj);


Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

Rendering JButton to get the JCheckBox behavior in a JTable by using images does not update my table -