I'm currently developing a JavaScript applet that involves replacing array entries in a given string with elements from another array. Here is the code I have so far:
const str = "Lion, Unicorn, Unicorn";
const arr1 = ["Lion", "Unicorn"];
const arr2 = ["Fox", "Hound"];
const newStr = str.replaceAll(arr1[0], arr2[0]) //returns "Fox, Unicorn, Unicorn"
The output I want to achieve is:
Fox, Hound, Hound
.
I am looking to create a function that repeats this process for each item in an array, but I'm unsure of how to proceed.
Thank you!