Skip to content
Advertisement

I am getting error push() is not a function while pushing element in array?

I am getting error push() is not a function while pushing element in >array? giving me error lik arry.push is not a function

 var abc=["get","get","get","get","get","get","get","get","get",];
    
     for(i=0;i<abc.length;i++){

    let a=abc[i].push("mate");
 
   console.log(abc);
    }

Advertisement

Answer

You should delete the [i] in abc[i].push() because abc[i] is string, but the .push() method works for arrays. Therefore you should use abc.push() instead of abc[i].push().

Advertisement