//Insert Element At the End

function InsertElement(arr,key,n,capcity1){
    //Check Array Size First Before insert to check either we have space to add 
    if(n >= capcity1)
        return n;
    
    //Add Value the n index
    arr[n]=key
    return (n+1);
}

var arr = Array<number>(15);
arr[0]=1;
arr[1]=2;
arr[2]=10;
arr[3]=13;
arr[4]=7;
arr[5]=11;
var n=6;
var key = 29;
var capcity = 15;

console.log('Before Insert');
for(let i=0;i<n;i++){
    console.log(arr[i]+' ');
}

n = InsertElement(arr,key,n,capcity); 

console.log('After Insert');
for(let i=0;i<n;i++){
    console.log(arr[i]+' ');
}



Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: