Skip to content
Advertisement

Use event.target.name instead of hardcoded value when setting state in nested array

I have a nested array i add dynamically to my state and therefore i dont know the key/name of the nested array and I can not give the key/name of the nested array when i need to add, update, iterate or remove somethings in the array. An example is the function addClick

JavaScript

The comment contains the way i am thinking it should be. So instead of writing “DevOps” which is the key/name of the array, i want it to use the value of “event.target.name”, but it will not use it. So how do i use the value when setting state of “value”??

other examples:

JavaScript

JavaScript

Advertisement

Answer

Close. Using a variable/expression/etc. as a property name in an object literal requires bracket notation:

JavaScript

or:

JavaScript
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement