Show Output
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>JavaScript Sort an Array Alphabetically</title> </head> <body> <script> var fruits = ["Banana", "Orange", "Apple", "Papaya", "Mango"]; var sorted = fruits.sort(); document.write(fruits + "<br>"); // Outputs: Apple,Banana,Mango,Orange,Papaya document.write(sorted); // Outputs: Apple,Banana,Mango,Orange,Papaya </script> </body> </html>