My task involves manipulating the following text:
const a: string = 'I like orange, blue, black, pink, rose, yellow, white, black';
Along with this string:
const b: string =['black', 'yellow'];
The objective is to replace all instances of black and yellow in string a with violet. Thus, the final result should appear as follows on the screen:
'I like orange, blue, violet, pink, rose, violet, white, violet'.
I am aware of the replace() function but I am unsure how to use b as an argument. Can someone provide guidance?
If possible, I would also like to implement an input field for the replacement colors instead of hardcoded values. This way, I could dynamically type any desired color into the text. Thank you for your assistance!