Show Output
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>jQuery Create String from Array Elements</title> <script src="https://code.jquery.com/jquery-3.5.1.min.js"></script> <script> $(document).ready(function(){ var superheros = ["Superman", "Hulk", "Spiderman"]; var fight = superheros.join("-vs-"); $("input[type='button']").click(function(){ alert(fight); }); }); </script> </head> <body> <p><input type="button" value="Fight List"></p> <p>Click the above button and you will get the string created by joining the elements of superheroes array.</p> </body> </html>