I have an array of animals:
animals = [
{name:"Dog", color_id:1, color:"Red" ....},
{name:"Cat", color_id:2, color: "Blue"....},
{name:"Fish", color_id:3, color:"Purple"...},
{name:Mouse, color_id:2, color:"Blue" ...}
]
My goal is to create a list of unique colors:
colorList = [{value:1, label:"Red"}, {value:2, color:"Blue"}, {value:3, color:"Purple"}]
I attempted to do this using the following code snippet, but it did not give me the desired results:
animals.forEach(function(currAnimal){
var i = propertyTypeOptions.findIndex(animals => animals.value == colorList.value);
if(i <= -1){
propertyTypeOptions.push({value: currAnimal.color_id, label: currAnimal.color});
}
})