title: How To Use An Array Of Object Outside For Loop Created In The For Loop?
body: <p>I am a newbie in Javascript. So, forgive me for any mistakes related to terminology. I have created an array inside a for loop. Here is the code. Whenever I use console outside the condition and loop only a single line is shown. I have updated the question and added the array. I want to select the array which has rice and see it outside of the for loop.</p>
  <p><a href="https://i.stack.imgur.com/x3nQD.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/x3nQD.png" alt="enter image description here" /></a></p>
  <p>I need to see like this whenever I use console outside the loop:
  <a href="https://i.stack.imgur.com/2RzsO.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/2RzsO.png" alt="enter image description here" /></a></p>
  <pre><code>  const datastructure= [
  
      {&quot;months&quot;:&quot;January&quot;,&quot;productname&quot;:&quot;Rice&quot;,&quot;production&quot;:&quot;10&quot;,&quot;hector&quot;:&quot;2&quot;},
      {&quot;months&quot;:&quot;February&quot;,&quot;productname&quot;:&quot;Rice&quot;,&quot;production&quot;:&quot;11&quot;,&quot;hector&quot;:&quot;2&quot;},
      {&quot;months&quot;:&quot;March&quot;,&quot;productname&quot;:&quot;Rice&quot;,&quot;production&quot;:&quot;12&quot;,&quot;hector&quot;:&quot;2&quot;},
      {&quot;months&quot;:&quot;April&quot;,&quot;productname&quot;:&quot;Rice&quot;,&quot;production&quot;:&quot;13&quot;,&quot;hector&quot;:&quot;2&quot;},
      {&quot;months&quot;:&quot;January&quot;,&quot;productname&quot;:&quot;Fruit&quot;,&quot;production&quot;:&quot;14&quot;,&quot;hector&quot;:&quot;2&quot;},
      {&quot;months&quot;:&quot;February&quot;,&quot;productname&quot;:&quot;Fruit&quot;,&quot;production&quot;:&quot;15&quot;,&quot;hector&quot;:&quot;2&quot;},
      {&quot;months&quot;:&quot;Markch&quot;,&quot;productname&quot;:&quot;Fruit&quot;,&quot;production&quot;:&quot;16&quot;,&quot;hector&quot;:&quot;2&quot;},
      {&quot;months&quot;:&quot;April&quot;,&quot;productname&quot;:&quot;Fruit&quot;,&quot;production&quot;:&quot;16&quot;,&quot;hector&quot;:&quot;2&quot;},
  
  ];
  for(i in datastructure){
    if(datastructure[i].productname==&quot;Rice&quot;)
    {
    var months=datastructure[i].months
    var  productname=datastructure[i].productname
    var  production=datastructure[i].production
    var  hector=datastructure[i].hector
  
  
  
  formatedata =[({'months':months, 'productname':productname,'production':production,'hector':hector})];
  
  
   console.log(formatedata)
    }
  
  
  }
  </code></pre>