How to append an item into a JavaScript array?

JavascriptWeb DevelopmentFront End Technology

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:

Live Demo

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

Output

marketing,technical,finance,sales,HR
raja
Published on 12-Feb-2018 12:11:14
Advertisements