How can I get data from a field name when the name changes dynamically in Javascript? -


i have following code:

            switch (entitytype) {                 case "exam":                     entityid = formdata.examid;                     idcolumn = 'examid';                     break;                 case "subject":                     entityid = formdata.subjectid;                     idcolumn = 'subjectid';                     break;             } 

it's repeated more times showing 2 case values here. believe it's possible values idcolumn getting lowercase of entitytype , adding id. there way extract value in formdata field based on entitytype without having manually code many times.

you can replace whole with

  idcolumn = entitytype.tolowercase()+'id';   entityid = formdata[idcolumn]; 

i'd suggest read mdn's working objects.


Comments

Popular posts from this blog

c++ - Function signature as a function template parameter -

How to call a javascript function after the page loads with a chrome extension? -

algorithm - What are some ways to combine a number of (potentially incompatible) sorted sub-sets of a total set into a (partial) ordering of the total set? -