Preview:
 /*
        Function to insert a new element to the given position using for loop
        @param array, position, element
      */
      const insertFun = (arr, pos, el) => {
        if (pos <= arr.length && typeof pos === "number") {
          for (let i = arr.length - 1; i >= 0; i--) {
            if (i >= pos) {
              data[i + 1] = data[i];
              if (i === pos) {
                data[i] = el;
              }
            }
          }
          return arr;
        } else {
          alert("Out of Range");
        }
      };
downloadDownload PNG downloadDownload JPEG downloadDownload SVG

Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!

Click to optimize width for Twitter