Horje Website
JavaScript ES6 Insert Array Elements into another Array using Spread Operator – JavaScript Code

JavaScript ES6 Insert Array Elements into another Array using Spread Operator

JavaScript ES6 Insert Array Elements into another Array using Spread Operator - JavaScript Code


 
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8">
  5. <title>JavaScript ES6 Insert Array Elements into another Array using Spread Operator</title>
  6. </head>
  7. <body>
  8. <script>
  9. let pets = ["Cat", "Dog", "Parrot"];
  10. let bugs = ["Ant", "Bee"];
  11. // Creating an array by inserting elements from other arrays
  12. let animals = [...pets, "Tiger", "Wolf", "Zebra", ...bugs];
  13. document.write(animals); // Cat,Dog,Parrot,Tiger,Wolf,Zebra,Ant,Bee
  14. </script>
  15. </body>
  16. </html>



Try Your Self ->



Published:
September 12, 2020
Author:
admin
Category:
JavaScript Example, Javascript Source Code
Views:
17

This article was posted in JavaScript Example, Javascript Source Code and tagged , , . Bookmark the permalink. Follow comments with the RSS feed for this post.Post a Comment or leave a trackback: Trackback URL.

Leave a Reply

Your email address will not be published. Required fields are marked *

 

Horje © 2011 - 2022