Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

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.
Source by developer.mozilla.org #
 
PREVIOUS NEXT
Tagged: #remove #replacing #element #array #javascript
ADD COMMENT
Topic
Name
2+9 =