I want to make a function that has two arrays in it. The first array contains numbers and the 2nd contains letters and numbers. I want to compare them, and if a certain element within the 2nd array is also on the 1st array, then to replace the element of the 1st array to something else. This is the example array i've written:
const array1 = ['1', '2', '3', '4', '5']
const array2 = ['a', 'b' '3', '2', 'c']
So the 2nd array and the 1st array both have numbers 3 and 2. This is my code for trying to compare the values:
const arraycompare = array1.some(x => array2.includes(x))
const finalarray = array1.replace(arraycompare, `${arraycompare} - also found in array2`
console.log(finalarray)
However this doesn't work because arraycompare returns a boolean and not the value of the elements that it had compared and found that they are present in both arrays. So how am I supposted to fix this and make it so that arraycompare and finalarray work?