Javascript Array - concat method
The concat method is helpful if you wish to append an array to another existing array. Here is a simple example.
Take a look at the following example
<html> <body> <script type="text/javascript"> var us_cars = ["Ford", "GM"]; var foreign_cars =["Toyota", "Honda"]; var all_cars = []; all_cars = us_cars.concat(foreign_cars); document.writeln('All cars :' + all_cars + '<br />'); </script> </body> </html> |
Try this example online here .
With the concat method, you can not only join two or more arrays, but can also add additional elements at the end of it. See this example
<html> <body> <script type="text/javascript"> var us_cars = ["Ford", "GM"]; var foreign_cars =["Toyota", "Honda"]; var all_cars = []; var best_Car = "Hyundai"; all_cars = us_cars.concat(foreign_cars,best_Car); document.writeln('All cars :' + all_cars + '<br />'); </script> </body> </html> |
Try this example online here .