1// remove element at certain index without changing original
2let arr = [0,1,2,3,4,5]
3let newArr = [...arr]
4newArr.splice(1,1)//remove 1 element from index 1
5console.log(arr) // [0,1,2,3,4,5]
6console.log(newArr)// [0,2,3,4,5]
1fruits = ['Banana', 'Orange', 'Apple', 'Mango'];
2
3removeFruitByIndex(index: number) {
4 this.fruits = [
5 ...this.fruits.slice(0, i),
6 ...this.fruits.slice(i + 1, this.fruits.length),
7 ];
8}
9
10
11removeFruitByValue(fruite: string) {
12 const i = this.descriptionsList.indexOf(fruite);
13 this.fruits = [
14 ...this.fruits.slice(0, i),
15 ...this.fruits.slice(i + 1, this.fruits.length),
16 ];
17}
1var fruits = ["Banana", "Orange", "Apple", "Mango", "Kiwi"];
2document.getElementById("demo").innerHTML = fruits;
3
4function myFunction() {
5 fruits.splice(2, 2);
6 document.getElementById("demo").innerHTML = fruits;
7}
1const items = ['a', 'b', 'c', 'd', 'e', 'f']
2const i = 2
3const filteredItems = items.slice(0, i).concat(items.slice(i + 1, items.length))
4// ["a", "b", "d", "e", "f"]
5
1let myFish = ['angel', 'clown', 'drum', 'mandarin', 'sturgeon']
2let removed = myFish.splice(3, 1)
3
4// myFish is ["angel", "clown", "drum", "sturgeon"]
5// removed is ["mandarin"]