How can I remove a specific item from an array using JavaScript ?

There are two main approaches

  1. splice()
  2. delete

 


  splice() : splice  is the most conman  approaches  remove a specific item from 
  an array using JavaScript  

  syntax : MyArray.splice(index, 1);

  let country = ['USA', 'UK', 'UAE', 'India']
  let removed = country.splice(2, 1);


  Result :  ['USA', 'UK', 'India']

  delete : Delete is second way to remove an item from an array in JavaScript, 

  syntax: delete MyArray[index]



   let country1 = ['USA', 'UK', 'UAE', 'India']

   let removed = delete country1[2]



   Result :  ['USA', 'UK', undefined , 'India']

   Better to use splice() it is simple way to remove a specific item from an array using 
   JavaScript  , when you use delete for an array you could get wrong results 
   for MyArray.length

   Here 

   country1.length  = 4 


   country.length  = 3 





WhatsApp forward Message Wp20.ru link, is it trustworthy to click ?

No of course not , Last week onward wp20.ru link message are circulating on WhatsApp. You might get this message from friends / family circle, please don’t click it it is a virus link.It install automatically virus to you browser.unfortunately any of your trusted fried shared that Wp20.ru and you already opened that website please clear cache & cookies .if you dont know how to do that please follow this link https://support.google.com/accounts/answer/32050?hl=en&co=GENIE.Platform%3DAndroid&oco=1 and don’t forgot to restart your system after clearing cache & cookies

Almost all different antivirus vendors listed this link as Malware/Phishing/ Suspicious link. So stay away from this link, If you see a link starting with wp20.ru don’t click it..

WhatsApp forward Message Wp20.ru link