const arrA = a[0].trim().split("\n");
// [ "123", "1234", "12345", "123456" ]
const arrB = b[0].trim().split("\n");
// [ "a", "b", "c", "d" ]
const arrAB = arrA.map((str, index) => `${arrB[index]}: ${str}`);
// [ "a: 123", "b: 1234", "c: 12345", "d: 123456" ]
arrAB.join("\n")
/*
"a: 123
b: 1234
c: 12345
d: 123456"
*/
upd. ..и тут вопрос полностью изменили.
const a = ['123', '1234', '12345', '123456'];
const b = ['a', 'b', 'c', 'd'];
const replace = (search, a, b) => {
const result = a.slice(); // копия
const index = a.indexOf(search);
if (index > -1) result.splice(index, 1, b[index]);
return result;
}
replace('1234', a, b)
// [ "123", "b", "12345", "123456" ]