Jquery how to find an Object by attribute in an Array
问题 Given I have an array of "purpose" objects: //array of purpose objects: var purposeObjects = [ {purpose: "daily"}, {purpose: "weekly"}, {purpose: "monthly"} ]; (for simplicity i am omitting other attributes) Now I want to have a method that returns a specific one of the objects if a matching purpose name is found. This is not working: function findPurpose(purposeName){ return $.grep(purposeObjects, function(){ return this.purpose == purposeName; }); }; findPurpose("daily"); but it actually