My Axios request pulls in an array of objects named 'uniquecolors'. Here is what it looks like:
mycolors
color: [GREEN, RED, BLUE, YELLOW, ORANGE,ORANGE,GREEN,]
color: [GREEN, RED, BLUE, YELLOW, ORANGE,ORANGE,GREEN,]
color: [GREEN, RED, BLUE ]
color: [YELLOW, ORANGE]
color: [GREEN, GREEN,GREEN,RED]
color: [ORANGE,GREEN,ORANGE,GREEN,RED]`
I want to retain only the colors 'RED' and 'GREEN' for each object
I intend to substitute 'RED' with 'Crimson'
I aim to swap 'GREEN' with 'Sage'
`methods: .... const uniquecolorscationwithduplicates = uniquecolors .toString() .replace("RED", "Crimson") .replace("GREEN", "Sage") .replace("YELLOW,", "") .split("|");``
The current result retains all original colors and appends 'Crimson' and 'Sage'. Thus it now displays 'GREEN,Sage,RED,Crimson,BLUE, YELLOW, ORANGE' without replacement.
What could be causing this?
In attempting to remove colors, I resorted to replacing them with blank strings. I realize this may not be ideal coding practice; any advice on better approaches would be appreciated.
Ultimately, I hope to alter all occurrences of colors during page rendering. Any guidance on how to achieve this would be welcomed.
Thank you in advance