In my code, I'm trying to map through an array and find an element. Then, I will replace that element with a string. The problem is, the index is -1. And, wrong element is replaced with the string. What is the cause of this problem and how can I fix this? My stackblitz and code is down below.
JS:
const arr = ['this', 'is', '<a/>', 'apple'];
const index = arr.indexOf(arr.includes('<'));
console.log(index);
const newArray = arr.map((arrayElement) => {
arr.splice(index, 1, 'blocked');
return arrayElement;
});
console.log(newArray);