Computer >> Computer tutorials >  >> Programming >> Javascript

How to append an item into a JavaScript array?


To append an item to a JavaScript array, use the push() method.

Example

You can try to run the following code to append an item:

<html>
   <body>
      <script>
         var arr = ["marketing", "technical", "finance", "sales"];
         arr.push("HR");
         document.write(arr);
      </script>
   </body>
</html>

Output

marketing,technical,finance,sales,HR