Get the length of a JavaScript Object or Array

.size()


Description: Get the size of a JavaScript Object, Array or a length of a string.


Example:

<!doctype html>
    <html lang="en">
    <head>
      <meta charset="utf-8">
      <title>size demo</title>
      <script src="http://code.bitsycode.com/bitsycode-latest.min.js"></script>
    </head>
    <body>
      
      <div class="container">This is a test string</div><br />
      <button onclick="getSize()">Get length of string</button>
      
      <script type="text/javascript">
         
         function getSize() {
            var str = bitsyCode('.container').text();
            var result = bitsyCode.size(str);
            
            alert(result);
         }
         
      </script>
     
    </body>
    </html>

Preview:

This is a test string

  • Usage

    • How to use:

      Get the length of a JavaScript object, array or string with this method.

    • Length of Object:
      bitsyCode.size({});
    • Length of Array
      bitsyCode.size([]);
    • Length of String
      bitsyCode.size('');
  • Options

    • What options are there:

      There are no options for this method.

  • Returns

    • Returns: 0 // Returns a numeric value with the length
Share