Matching text field value with array value

You want to work with an object with named members.

var names = 
    'dog': 'good',
    'cat': 'bad'

supposing you user input is stored in variable userinput and your output should be in variable output can the do

for(var membername in names)
    if(userinput == membername)
         output = names[membername];

Browse More Popular Posts

Leave a Comment