Show Output
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>Turn JavaScript Object into an Array</title> <script src="https://code.jquery.com/jquery-3.5.1.min.js"></script> </head> <body> <script> var myObj = { 1: ["Peter", "24"], 2: ["Harry", "16"], 3: ["Alice", "20"] }; // Transform JS object to an array var array = $.map(myObj, function(value, index){ return [value]; }); console.log(array); // Output: [["Peter", "24"], ["Harry", "16"], ["Alice", "20"]] </script> <p><strong>Note:</strong> Please check out the browser console by pressing the f12 key on the keyboard.</p> </body> </html>