Modify a single property of an object in a Map
P粉884667022
2023-08-03 10:24:02
<p>Suppose I have a mapped data type. </p>
<pre class="brush:php;toolbar:false;">testMap: Map<string, any></pre>
<p>The string value is my key, and any value is an object in that map. <br /><br />The object might look like this:</p><p><br /></p>
<pre class="brush:php;toolbar:false;">{ name: 'testName', age: 20}</pre>
<p>Suppose the user selects an element with a key via a drop-down menu. <br /><br />How can I now change the name of the object to the corresponding key by this key? <br /><br />I have iterated through the map using a forEach loop and tried changing the properties using Map.get() and Map.set(). Unfortunately, this didn't work. </p><p><br /></p>
Like this