javascript - get matched key in Object.keys(obj) -
i have object containing team members.
if incomingmessage
contains 1 of keys want return 1 of messages them.
is there way can matched key in code below?
const team = { hank: ['good guy', 'wonderful man'], chuck: ['jerk', 'buttmunch'] } let incomingmessage = 'tell me chuck'; if(object.keys(team).indexof(incomingmessage) > -1) { console.log(team); //is there way here can //key has matched? in case, 'chuck' }
logic backwards ... need check if key exists in message , not other way around.
something like:
object.keys(team).foreach(function(key) { if (incomingmessage.indexof(key) > -1){ console.log('found ' + key +' in message') } });
Comments
Post a Comment