How can I remove a specific item from an array?
In Javascript, you can use splice to remove a specific item.Ex:-
var items =[1,4,6,13,67];var itemToBeRemoved = 13; items.splice(items.indexOf(itemToBeRemoved),1); // find the index of item and delete "1" itemconsole.log(items);
var items =[1,4,6,13,67];
var itemToBeRemoved = 13;
items.splice(items.indexOf(itemToBeRemoved),1); // find the index of item and delete "1" item
console.log(items);
In C# , you can use RemoveAt() method.
static void Main() { List<int> items= new List<int>(){1,2,3,5,13,64}; int itemToBeRemoved = 5; items.RemoveAt(items.IndexOf(itemToBeRemoved)); Console.WriteLine(string.Join(",", items)); }
static void Main()
{
List<int> items= new List<int>(){1,2,3,5,13,64};
int itemToBeRemoved = 5;
items.RemoveAt(items.IndexOf(itemToBeRemoved));
Console.WriteLine(string.Join(",", items));
}