Rajanikant Hawaldar
How can I remove a specific item from an array?

How can I remove a specific item from an array?

By Rajanikant Hawaldar in JavaScript on Sep 27 2020
  • Kiran Mohanty
    Sep, 2020 30

    In Javascript, you can use splice to remove a specific item.
    Ex:-

    1. var items =[1,4,6,13,67];
    2. var itemToBeRemoved = 13;
    3. items.splice(items.indexOf(itemToBeRemoved),1); // find the index of item and delete "1" item
    4. console.log(items);

    In C# , you can use RemoveAt() method.

    1. static void Main()
    2. {
    3. List<int> items= new List<int>(){1,2,3,5,13,64};
    4. int itemToBeRemoved = 5;
    5. items.RemoveAt(items.IndexOf(itemToBeRemoved));
    6. Console.WriteLine(string.Join(",", items));
    7. }

    • 1


Most Popular Job Functions


MOST LIKED QUESTIONS