Computer >> Computer tutorials >  >> Programming >> Javascript

How can I convert the arguments object to an array in JavaScript?


Use the Array.from() method in JavaScript to convert the arguments object to an array

Example

Live Demo

<!DOCTYPE html>
<html>
   <body>
      <script>
         function sortArg() {
            var args = Array.from(arguments);
            return args.sort();
         }
         document.write(sortArg('x', 'y', 'z', '20', '66', '35','john', 'david'));
      </script>
   </body>
</html>