title: Clearing the array before generating the same
body: <p>I am facing a problem in clearing an array before reconstructing it. This is the code I have written</p>
  
  <p>this is the code when a button with saveBtn as id is clicked</p>
  
  <pre><code>jQuery("#saveBtn").on('click',function(){
      var selectedColsArray =[];
      jQuery('#editDisplay li:not(.strike)').each(function(i){
          selCols = jQuery(this).text();
          selectedColsArray.push(selCols);
      });
      var divID = jQuery(this).parents().eq(2).attr('id');
      hideCols(selectedColsArray);
      jQuery('#editWindow').hide();
  });
  
  function hideCols(selectedCols){
      availableColsArr = [];
      jQuery('#documentReferences .dataTables_scrollHeadInner th').each(function(){
          columnName = jQuery(this).text();
          availableColsArr.push(columnName);
      });
      var result = [];
      var i = 0;
      jQuery.grep(availableColsArr, function(j) {
          if (jQuery.inArray(j, selectedCols) == -1) result.push(j);
          i++;
      });
  
      jQuery('#documentReferences .dataTables_scrollHeadInner th').each(function(){
          for(var k=0;k&lt;result.length;k++){
              colText = jQuery(this).text();
              if(colText == result[k]){
                  var colID = jQuery(this).attr('class').split(/\b/)[0];
                  jQuery('.'+colID).hide();
              }
          }
  
          for(var k=0;k&lt;selectedCols.length;k++){
              colText1 = jQuery(this).text();
              if(colText1 == selectedCols[k]){
                  var colID = jQuery(this).attr('class').split(/\b/)[0];
                  jQuery('.'+colID).show();
              }
          }
  
      });
  
  }
  </code></pre>
  
  <p>But when I click on the save button the array is not getting reconstructed. 
  How can I clear it and the construct a new array every time the save button is clicked.
  I tried using selectedColsArray.length = 0 after declaring the array. but doesn't work</p>