<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: nextstep</title>
    <description>The latest articles on DEV Community by nextstep (@nextstep).</description>
    <link>https://dev.to/nextstep</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F405626%2F148d5994-4966-4bda-8226-43d628bf8635.png</url>
      <title>DEV Community: nextstep</title>
      <link>https://dev.to/nextstep</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/nextstep"/>
    <language>en</language>
    <item>
      <title>Convert JS associate array to JSON</title>
      <dc:creator>nextstep</dc:creator>
      <pubDate>Thu, 03 Jun 2021 02:02:52 +0000</pubDate>
      <link>https://dev.to/nextstep/first-post-4409</link>
      <guid>https://dev.to/nextstep/first-post-4409</guid>
      <description>&lt;p&gt;An associative array is an array with string keys rather than numeric keys[1]. Sometimes, we need to convert the array into a JSON object. Here is a single line of code to do it;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let jsArray = []
jsArray['name'] = 'foo'
jsArray['birthday'] =  '04-04-2011'

console.log(jsArray['name'])

if (Object.keys(jsArray).length !== 0) {       
   let json = Object.assign({}, jsArray)
   console.log(json)
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;output:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;foo
{
name:"foo",
birthday:"04-04-2011"
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://playcode.io/776216/"&gt;https://playcode.io/776216/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Readings:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;[1] &lt;a href="http://dyn-web.com/javascript/arrays/associative.php"&gt;http://dyn-web.com/javascript/arrays/associative.php&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

</description>
    </item>
  </channel>
</rss>
