How to replace an element in an array with TypeScript

1 Answer

0 votes
const arr = ['typescript', 'php', 'python', 'c', 'c#', 'c++'];
   
const index = arr.indexOf('c'); 
 
if (index !== -1) {
    arr[index] = 'go';
}
   
console.log(arr); 
   
   
   
   
/*
run:
   
["typescript", "php", "python", "go", "c#", "c++"] 
   
*/

 



answered Jul 6, 2022 by avibootz
...