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

JavascriptWeb DevelopmentFront End Technology

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>
raja
Published on 30-Jan-2018 11:47:48
Advertisements