title: Netsuite Javascript Grab Last Array Value
body: <p>So I found some info on this site on how to go about grabbing the value of the last index of an array. I have an Array that is of an unknown length. It builds based on a search of results. For example:</p>
  
  <pre><code>var custid = nlapiGetFieldValue('entity');
      var custRecord = nlapiLoadRecord('customer', custid);
      var itemPriceLineCount = custRecord.getLineItemCount('itempricing');
      for (var i = 1; i &lt;= itemPriceLineCount; i++) {
  
          var priceItemId = [];
          priceItemId = custRecord.getLineItemValue('itempricing', 'item', i);
          if (priceItemId == itemId) {
              var histCol = [];
              histCol[0] = new nlobjSearchColumn('entity');
              histCol[1] = new nlobjSearchColumn('totalcostestimate');
              histCol[2] = new nlobjSearchColumn('tranid');
              histCol[3] = new nlobjSearchColumn('trandate');
              var histFilter = [];
              histFilter[0] = new nlobjSearchFilter('entity', null, 'is', custid);
              histFilter[1] = new nlobjSearchFilter('item', null, 'is', itemId);
              var histSearch = nlapiSearchRecord('invoice', null, histFilter, histCol);
              for (var h = 0; h &lt;= histSearch.length; h++) {
                  var itemRate = new Array();
                  var histSearchResult = histSearch[h];
                  itemRate = histSearchResult.getValue('totalcostestimate');
  
  
  
  
              }
  
          }
  
      }
  </code></pre>
  
  <p>Now when I use:</p>
  
  <p>var last_element = itemRate[itemRate.length - 1];</p>
  
  <p>It gives me the number of digits/placeholders in each element of the array. So as per my example I know my array holds the values of .00 and 31.24 because I put them there for a test. So last_element will result in 3 and 5. How can I grab the value 31.24 or the last element period? I need the value not the number of digits.</p>