<?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: pampapati</title>
    <description>The latest articles on DEV Community by pampapati (@pampapati).</description>
    <link>https://dev.to/pampapati</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%2F882884%2F7074ca27-1d7d-45e4-a9b4-2ea74eabef98.png</url>
      <title>DEV Community: pampapati</title>
      <link>https://dev.to/pampapati</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/pampapati"/>
    <language>en</language>
    <item>
      <title>JavaScript for...in iteration</title>
      <dc:creator>pampapati</dc:creator>
      <pubDate>Sun, 03 Jul 2022 09:45:49 +0000</pubDate>
      <link>https://dev.to/pampapati/javascript-forin-iteration-47oe</link>
      <guid>https://dev.to/pampapati/javascript-forin-iteration-47oe</guid>
      <description>&lt;p&gt;In this post will try to showcase different ways for the iterations.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;using forEach&lt;/li&gt;
&lt;li&gt;using for...of&lt;/li&gt;
&lt;li&gt;using for...in&lt;/li&gt;
&lt;li&gt;using for
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let list = [1,2];
list.newCustomElement = true;

list.forEach( (item)=&amp;gt;{
console.log(item);
});

//Output 
1
2


for(let item of list){
console.log("using of",item);
}

//Output 
"using of", 1
"using of", 2

for(let item in list){
console.log("using in",item);
}

//Output 
"using in", "0"
"using in", "1"
"using in", "newCustomElement"



for(let i=0;i&amp;lt;list.length;i++){
console.log(list[i]);
}
//Output 
1
2

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;Don't use for...in to iterate the array , if the order is important&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Will see another example for better understanding of for..in&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
const Employee= {
    name: 'John',
    dept: 'IT',
    age: 29
}


for ( let key in Employee) {
    console.log(key);
}

Output:
"name"
"dept"
"age"

for ( let key in Employee) {
    console.log('key: ',key,' value:', Employee[key]);
}

Output:
"key: ", "name", " value:", "John"
"key: ", "dept", " value:", "IT"
"key: ", "age", " value:", 29
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In above example for...in is used to print properties on Employee object. &lt;/p&gt;

&lt;p&gt;First for loop in above example will showcase that object keys are printed using iterator &lt;strong&gt;key&lt;/strong&gt;, it wont print the values of property.&lt;/p&gt;

&lt;p&gt;Second for loop in above example will showcase how to print keys and the values of property.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Flat Nested Array: JavaScript</title>
      <dc:creator>pampapati</dc:creator>
      <pubDate>Sun, 26 Jun 2022 08:32:48 +0000</pubDate>
      <link>https://dev.to/pampapati/flat-nested-array-javascript-930</link>
      <guid>https://dev.to/pampapati/flat-nested-array-javascript-930</guid>
      <description>&lt;p&gt;Flat nested array without using built-in methods. Recursive program example&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const arr = [1,2,[3,4],5,[6,[7,8],9],10];

function flatArray(input,output){   
  input.forEach( (value)=&amp;gt;{    
    if(typeof value== 'object'){
      flatArray(value,output);
    }else{
      output.push(value);
    }    
  });
  return output;  
}

console.log(flatArray(arr,[]));
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>javascript</category>
      <category>programming</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>How to create JavaScript Objects</title>
      <dc:creator>pampapati</dc:creator>
      <pubDate>Sun, 26 Jun 2022 08:19:10 +0000</pubDate>
      <link>https://dev.to/pampapati/how-to-create-javascript-objects-5fed</link>
      <guid>https://dev.to/pampapati/how-to-create-javascript-objects-5fed</guid>
      <description>&lt;p&gt;-using {}&lt;/p&gt;

&lt;p&gt;-using new Object()&lt;/p&gt;

&lt;p&gt;-using Object.create()&lt;/p&gt;

&lt;p&gt;-using Object.assign()&lt;/p&gt;

&lt;p&gt;-using ES6 Class &lt;/p&gt;




&lt;p&gt;Object Creation Using ES6 Class:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class Employee{
   constructor(name,dept){
       this.name = name;
       this.dept = dept;
   }
}

const firstEmployee = new Employee('Pavan','IT');
console.log(firstEmployee);

Output // 
{
name: 'Pavan', 
dept: 'IT'
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>programming</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Format Array : JavaScript</title>
      <dc:creator>pampapati</dc:creator>
      <pubDate>Sun, 26 Jun 2022 07:42:47 +0000</pubDate>
      <link>https://dev.to/pampapati/format-array-javascript-204o</link>
      <guid>https://dev.to/pampapati/format-array-javascript-204o</guid>
      <description>&lt;p&gt;Input: &lt;br&gt;
 &lt;code&gt;[&lt;br&gt;
  { x: 'a', order: 10},&lt;br&gt;
  { x: 'a', order: 3},&lt;br&gt;
  { x: 'a', order: 4},&lt;br&gt;
  { x: 'b', order: 3},&lt;br&gt;
  { x: 'b', order: 2},&lt;br&gt;
  { x: 'b', order: 1}&lt;br&gt;
]&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Output :&lt;br&gt;
 &lt;code&gt;{&lt;br&gt;
    “a":[{"x":"a","order":10},{"x":"a","order":3},{"x":"a","order":4}],&lt;br&gt;
    “b":[{"x":"b","order":3},{"x":"b","order":2},{"x":"b","order":1}]&lt;br&gt;
}&lt;/code&gt;&lt;/p&gt;

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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const arr = [
  { x: 'a', order: 10},
  { x: 'a', order: 3},
  { x: 'a', order: 4},
  { x: 'b', order: 3},
  { x: 'b', order: 2},
  { x: 'b', order: 1}
];

function formatArray(input){
  output = {};
  input.forEach( (value)=&amp;gt;{
    const xValue = value.x;
    if(Object.keys(output).includes(xValue+'')){
      output[xValue].push(value);
    }else{
      output[xValue] = [value];
    }    
  });
  return output;
}

console.log("output",formatArray(arr));
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



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