Ex: arr = [1,1,2,3];
If the values is 1 , it should change to red
If the values is 2 , it should change to blue
If the values is 3 , it should change to white
Expected output:
arr = [red,red,blue,white]
you can map your Array :
var nn = arr.map(e=> e == 1 ? e = "red" : e == 2 ? e = "blue" : e = "white")
Like so you are also able to filter out values that can't be mapped like 4 in this example.
[1,1,2,3,4].map(number => {
switch(number) {
case 1:
return 'red'
case 2:
return 'blue'
case 3:
return 'white'
default:
return undefined
}
}).filter(name => name)