• Match getstr() to object

    From Ephram@VERT/EPHRAM to All on Thu Jun 4 11:53:48 2020
    I have a script that gets a partial string that needs to be matched against anãobject/array.ããvar names = {ãAD:"Andorra",ãAE:"United Arab Emirates",ãAF:"Afghanistan",ãAG:"Antigua and Barbuda",ãAI:"Anguilla", ... };ããwrite(' \1cEnter Country Name to Lookup \1w'); ã var lookup = console.getstr();ã writeln('\r\n \1cLooking up \1w'+ lookup);ã for(var i = 0; i <= names.length; i++) {ã if(names[i][1].toUpperCase() ===ãindexOf(lookup).toUpperCase()) {ã writeln(' Found ' + names[i] + ' ' +ãnames[i][0] + ' ' + names[i][1]);ã }ã }ããif I enter, say lookup = 'Andor' it doesn't find anything ... ããany help would be appreciated :)ãããMy doctor said I have the body of a 25 year old
    ... and the mind of a 10 :-/ãã---ã þ Synchronet þ Realm of Dispair BBS - http://ephram.synchro.net:82ã
  • From echicken@VERT/ECBBS to Ephram on Thu Jun 4 11:23:33 2020
    Re: Match getstr() to objectã By: Ephram to All on Thu Jun 04 2020 11:53:48ãã Ep> var names = {ã Ep> AI:"Anguilla", ... };ã Ep> for(var i = 0; i <= names.length; i++) {ãã'names' is an Object, but you're treating it like an Array.ããYou could try something like:ããfor (var name in names) {ã // eg. name === 'AI' and names[name] === 'Anguilla'ã}ããOr something like:ããvar keys = Object.keys(names);ãfor (var i = 0; i < keys.length; i++) {ã // eg. keys[i] === 'AI' and names[keys[i]] === 'Anguilla'ã}ããOr something like:ããObject.keys(names).forEach(function (e) {ã // eg. e == 'AI' and names[e] === 'Anguilla'ã});ãã---ãechickenãelectronic chicken bbs - bbs.electronicchicken.comã þ Synchronet þ electronic chicken bbs - bbs.electronicchicken.comã
  • From Ephram@VERT/EPHRAM to echicken on Thu Jun 4 12:51:32 2020
    Re: Match getstr() to objectã > By: Ephram to All on Thu Jun 04 2020 11:53:48ãã > Ep> var names = {ã > Ep> AI:"Anguilla", ... };ã > Ep> for(var i = 0; i <= names.length; i++) {ãã > 'names' is an Object, but you're treating it like an Array.ãã > You could try something like:ãã > for (var name in names) {ã > // eg. name === 'AI' and names[name] === 'Anguilla'ã > }ãã > Or something like:ãã > var keys = Object.keys(names);ã > for (var i = 0; i < keys.length; i++) {ã > // eg. keys[i] === 'AI' and names[keys[i]] === 'Anguilla'ã > }ãã > Or something like:ãã > Object.keys(names).forEach(function (e) {ã > // eg. e == 'AI' and names[e] === 'Anguilla'ã > });ãã > echickenãããThank you, I appreciate that!ãããMy doctor said I have the body of a 25 year old ... and the mind of a 10 :-/ãã---ã þ Synchronet þ Realm of Dispair BBS - http://ephram.synchro.net:82ã