How to replace an element in an array with JavaScript

1 Answer

0 votes
const arr = ['javascript', 'php', 'python', 'c', 'c#'];
  
const index = arr.indexOf('php'); 

if (index !== -1) {
  	arr[index] = 'java';
}
  
console.log(arr); 
  
  
  
  
/*
run:
  
["javascript", "java", "python", "c", "c#"]
  
*/

 



answered Jul 6, 2022 by avibootz
...