Suppose I have the following json object, containing information about a set of people.
data=[{id:2, fname:"bob", lname:"roberts", common_name:null, email:"[email protected]", telephone:"555-555-5555", street:"333 Street St", city:"Salt Lake City", state:"UT", country:null, zip:"99999", dynamid:null, notes:null, director:false, contractor:false, contractor_need_agreement:false, shareholder:false, shares_held:0, company_id:1, created_at:"2016-02-23T10:15:09.339Z", updated_at:"2016-02-23T10:15:09.339Z", officer:false, snapshot:null, sign_term_voting:false, drag_liquidation_approval:false, rofr_consenter:false, investor_councel:false, ir_insured:false, issuer_signing_officer:false, issuer_registered_agent:false, issuer_councel:false, rep_lead_investor:false, rep_investor:false, rep_founder:false},
{id:1, fname:"John", lname:"Smith", common_name:null, email:"[email protected]", telephone:"555-555-5555", street:"333 Street St", city:"Salt Lake City", state:"UT", country:null, zip:"99999", dynamid:null, notes:null, director:false, contractor:false, contractor_need_agreement:false, shareholder:false, shares_held:0, company_id:1, created_at:"2016-02-23T10:15:09.327Z", updated_at:"2016-02-23T10:15:09.327Z", officer:false, snapshot:null, sign_term_voting:false, drag_liquidation_approval:false, rofr_consenter:false, investor_councel:false, ir_insured:false, issuer_signing_officer:false, issuer_registered_agent:false, issuer_councel:false, rep_lead_investor:false, rep_investor:false, rep_founder:false}]
Now I would like to implement some sort of auto-complete functionality in a text box that searches through each person's name (That is fname+" "+lname) looking for a match. Upon finding the match it either returns the person for whom it found a match or the id of that person.
I'm having a bit of trouble getting started on this. I figure I could write it out longhand where I use keyup to trigger a loop through the object, display those names matching the string and return the corresponding index upon clicking on one of them, but that seems like I'm reinventing the wheel.
Is there an efficient/best practice way to pull of this sort of functionality?