delete using splice javascript code example

Example 1: js array delete specific element

var arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 0];
var removed = arr.splice(2,2);
/*
removed === [3, 4]
arr === [1, 2, 5, 6, 7, 8, 9, 0]
*/

Example 2: remove or replacing element array in javascript

let myFish = ['angel', 'clown', 'mandarin', 'sturgeon']
let removed = myFish.splice(2, 0, 'drum')

// myFish is ["angel", "clown", "drum", "mandarin", "sturgeon"] 

let words: string[] = [
  'What',
  'I',
  'do',
  'create,',
  'I',
  'cannot',
  'not',
  'understand.',
];

let newWords = words.splice(2, 1, 'cannot');
let newWords2 = words.splice(5, 2, 'do not');
//console.log(newWords);
console.log(words.join(' '));

//What I cannot create, I do not understand.

Example 3: how to delete an element from an array in javascript

["bar", "baz", "foo", "qux"]list.splice(0, 2) // Starting at index position 0, remove two elements ["bar", "baz"] and retains ["foo", "qux"].