Hi im having some issues when it comes to updating a specific object in my list based on the key inside the object. Instead of updating the object in the array with the correct key it adds a new object inside the list with the key as an array and then adds the key and the chosen value to that list. My expected result is that it goes into the correct object with the same key and adds the selected value to that list in my example output image that would be "Annet". {Kategori:["Annet"]}
//Find key that matches chosen key
const addToFilter = valgtUnderFilter
.map((filter: any) => Object.keys(filter))
.flat()
.find((filter: string) => filter === valgtHovedFilter)
//map out all objects in list and try to update object with correct key
valgtUnderFilter.map((f: any) => {
//check if key exists in object (addToFilter = Kategori f = {Kategori : []})
if (addToFilter in f) {
return setValgtUnderFilter([...valgtUnderFilter, { [addToFilter]: [...[addToFilter], valg] }])
}
})
[![Output[1]](https://gamingcommission.club/i.sstatic.net/G1zv9.png)