title: Not able to change keys in JavaScipt dictionary
body: <p>I am a beginner, I want to replace spaces with hyphen from keys of JavaScript dictionary and get the keys back in dictionary</p>
  <p>eg. In <code>nameVars = {&quot;my name is&quot;:&quot;aman&quot;, &quot;age&quot;:22, &quot;my ed&quot;:&quot;btech&quot;}</code>
  I want resultant dictionary to be, <code>nameVars = {&quot;my-name-is&quot;:&quot;aman&quot;, &quot;age&quot;:22, &quot;my-ed&quot;:&quot;btech&quot;}</code>  I am doing it using</p>
  <pre><code>for(const [key, value] of Object.entries(nameVars)){
    key.replace(/\s+/g,&quot;-&quot;)`
  }
  </code></pre>
  <p>But my output is still same keys are not changing, please help I don't know JavaScript.</p>
  <p>Can someone tell what changes to make if instead this it is in format</p>
  <p><code>topicMessage = { topic: 'some_topic', messages: [{ 'myKey': '{&quot;data&quot;: {&quot;my name is &quot;:&quot;aman&quot;, &quot;age&quot;: 22, &quot;my ed&quot;: &quot;btech&quot;}, &quot;meta&quot;: {&quot;myAge&quot;:24, &quot;school&quot;:&quot;aps&quot;}}' }, { 'myKey2': '{ &quot;data&quot;: { &quot;my name is 2&quot;: &quot;aman&quot;, &quot;age&quot;: 22, &quot;my ed 2&quot;: &quot;btech&quot; }, &quot;meta&quot;: { &quot;myAge2&quot;: 24, &quot;school&quot;: &quot;aps&quot; } } ' }, { &quot;myKey3&quot;: '{&quot;data&quot;: {&quot;my name is 3&quot;:&quot;aman&quot;, &quot;age&quot;: 22, &quot;my ed 3&quot;: &quot;btech&quot;}, &quot;meta&quot;: {&quot;myAge&quot;:24, &quot;school&quot;:&quot;aps&quot;}}' } ] }</code></p>
  <p>here inside messaages of topicMessages in data part we have to make keys dash separated, and value for mykey, mykey2, mykey3 are in string form, so need to convert JSON.parse to object first and then again convert it back to string.</p>