0
function  removeArrayelements(arrayelements,element)
{
let result=[]
for(i=0;i<arrayelements.length;i++)
{
    if(arrayelements[i]==element)
    {
     arrayelements.splice(i,1)
       result=arrayelements
       return result
    }

    else{
    return `${element}is not present`
  }
}
}
console.log(removeArrayelements([2,5,9,6], 6))

remove a specific element from the array removeArrayelements([2,5,9,6], 6)//returns[2,5,9] removeArrayelements([2,5,9,6], 15)//returns 15 is not present

sri
  • 1
  • This has nothing to do with "removing items from array without breaking for loop". @sri the problem here is that your loop only checks first item and returns answer whether it's matching or not. What you need to do is remove `else` statement and move it's `return` at the end of the function, outside of the `for` loop. – vanowm Jun 24 '21 at 19:17

0 Answers0