Convert JavaScript Object & String to Array

.toArray()


Description: Convert an object into a JavaScript array.


Example:

<!doctype html>
    <html lang="en">
    <head>
      <meta charset="utf-8">
      <title>toArray demo</title>
      <script src="http://code.bitsycode.com/bitsycode-latest.min.js"></script>
    </head>
    <body>
      
      <div>{0: 'Zero', 1: 'One', 2: 'Two', 3: 'Three', 4: 'Four', 5: 'Five'}</div>
      <button onclick="toArray()">Convert to Array</button>
      
      <script type="text/javascript">
         
         function toArray() {
            var objField = {0: 'Zero', 1: 'One', 2: 'Two', 3: 'Three', 4: 'Four', 5: 'Five'};
            var result = bitsyCode.toArray(objField);
            
            alert(result);
         }
         
      </script>
     
    </body>
    </html>

Preview:

{0: 'Zero', 1: 'One', 2: 'Two', 3: 'Three', 4: 'Four', 5: 'Five'}

  • Usage

    • How to use:

      Convert JavaScript Objects and Strings to JavaScript Arrays

    • Convert an Object :

      bitsyCode.toArray({})
      Convert a String
      bitsyCode.toArray('String')
  • Options

    • What options are there:

      There are no options for this method.

  • Returns

    • Returns: [] //Converts and returns an array
Share