In this tutorial, we will learn how to insert the new elements in the array of data structures and algorithms with javaScript.

Insert new element in array:

 let arr = [58, 40, 60, 65, 50];
      let newEl = 30;
      let position = 3;

      for (let i = arr.length - 1; i >= 0; i--) {
        if (i >= position) {
          arr[i + 1] = arr[i];

          if (i === position) {
            arr[i] = newEl;
          }
        }
      }
      console.log(arr);

Same thing we can do using the Splice method like below:

arr.splice(position,0,newEl);

Topics covered:

Found this article helpful?

TutsCoder tutorials are free and ad-light — supported by readers like you. Buy me a coffee (or two ☕☕) as a token of appreciation and help keep Angular & Node.js content coming!

One-time. No subscription. 100% optional. 🙏 Every coffee counts!

Leave a Comment

Your email will not be published. Spam-free zone. ✌️

Available for Projects

Need Help With Your
Angular or Node.js Project?

7+ years of MEAN Stack experience. I build scalable Angular 21 apps, Node.js APIs, and SaaS products — delivered on time, every time.

7+ Years MEAN Stack Angular 21 + Nx Expert 20+ Projects Delivered Remote / Freelance