title: How to loop through object for finding a particular value using typescript and react?
body: <p>I want to hide a button if there is atleast one order or subareas that at least one orders whose status 'ACCEPTED' or 'DONE'.
  How can I hide the &quot;Hide me&quot; Menu item when either item has at least one area with order status 'ACCEPTED' OR 'DONE' or at least one area with subareas order with status 'ACCEPTED' or 'DONE'.</p>
  <p>Below is the react code with the item I am trying to process</p>
  <pre><code>function Parent() {
      const item = {
          owner: {
              id: '1',
              cognitoId: '2',
          },
          areas: [{
              id: '1',
              orders: [
                  {
                      id: '1',
                      status: 'ASSIGNED',
                  }, {
                      id: '2',
                      status: 'ACCEPTED',
                  } 
              ],
              subAreas: [
                  {
                      id: '1',
                      orders: [
                          {
                              id: '4',
                              status: 'DONE',
                          }
                      ],
                  }
              ]
          }, {
              id: '2',
              orders: [{
                      id: '3',
                      status: 'ASSIGNED',
                  }, {
                      id: '4',
                      status: 'ACCEPTED',
                  }
              ],
              subAreas: [{
                      id: '2',
                      orders: [{
                              id: '5',
                              status: 'DONE',
                          }, {
                              id: '6',
                              status: 'ACCEPTED',
                          }
                      ],
                  }
              ]
          }
      ]
  }
  
  return ({
      item &amp;&amp; item.owner &amp;&amp; item.owner.cognitoId &amp;&amp; (
           &lt; Menu &gt; Hide me &lt;  / Menu &gt; )
  });
  </code></pre>
  <p>}</p>
  <p>this Item is reference to how the data will look.<br />
  For additional information...Item is of type Item which is like below</p>
  <pre><code>export interface Item {
      id: string;
      name: string;
      areas?: Area[];
  }
  
  export interface Area {
      id: string;
      Orders?: Order[];
      subAreas?: Area[];
  }
  
  export interface Order {
      id: string;
      status: OrderStatus; //this is the one we are looping through
  }
  
  export interface OrderStatus {
      NEW = 'NEW',
      ASSIGNED = 'ASSIGNED',
      SENT = 'SENT',
      ACCEPTED = 'ACCEPTED',
      REJECTED = 'REJECTED',
      DONE = 'DONE',
  }
  </code></pre>
  <p><strong>what i have tried is like below</strong></p>
  <pre><code>const hasDoneAccepted = () =&gt; {
     return Object
        .keys(item)
            .some(key =&gt;
                (key === 'status' &amp;&amp;
                ['DONE', 'ACCEPTED'].indexOf(item[key]) &gt; -1) ||
                (typeof item[key] === 'object' &amp;&amp;
                hasDoneAccepted(item[key])));
   }
  </code></pre>
  <p>But this gives me an error like below,</p>
  <p>Element implicitly has any type because expression of type &quot;status&quot; cant be used on index type 'Item'. property status doesnt exist on type 'Item'.</p>
  <p>i am new to using typescript and not sure whats going wrong. could someone help me with this. thanks.</p>
  <p><strong>EDIT:</strong>
  using the solution provided</p>
  <pre><code>const hasAcceptedOrDoneOrders = 
      item.areas?.reduce&lt;Order[]&gt;((acc, area) =&gt; { //error here
          area.orders?.forEach(order =&gt; acc.push(order));
          area.subAreas?.forEach(subArea =&gt; subArea.orders?.forEach(order =&gt; 
              acc.push(order)));
              return acc;
      }, [])
      .some(order =&gt; order.status === &quot;ACCEPTED&quot; || order.status === &quot;DONE&quot;);
   }
  </code></pre>
  <p>this gives me an here at line</p>
  <pre><code>item.areas?.reduce&lt;Order[]&gt;((acc, area) =&gt; 
  </code></pre>
  <p>&quot;parsing error: expression expected&quot;</p>