title: Javascript: How to access element based on input parameter?
body: <p>Framework: Javascript, Jqgrid</p>
  
  <p>I have the below javascript function. It receives array of fields and Jqgrid. It sets the fields's required attribute to true. I want to pass an input string 'Required' and let the function set the element 'Required' to true. This way, I can reuse this function to set 'Integer', 'Email' attributes etc. I am looking for a feature similar to Java's reflection in Javascript. Can you please guide me if there is a way in Javascript to do that?</p>
  
  <pre><code>        function setRequiredFields(fields, grid){
          for (var i = 0; i &lt; fields.length; i++) {
              var colProp = $(grid).getColProp(fields[i]);                
              getColPropEditRules(colProp).Required = true;
              getColPropFormOptions(colProp).elmsuffix = " *";                
              $(grid).setColProp(fields[i], colProp);
          }
      }
  </code></pre>