title: Iterative function to intercept values by key
body: <p>I have a big JSON file that I want to intercept all the values that have the key <code>text</code> associated with them, for example:</p>
  <pre><code>    type&quot;:&quot;doc&quot;,
     &quot;content&quot;:[
        {
           &quot;type&quot;:&quot;paragraph&quot;,
           &quot;content&quot;:[
              {
                 &quot;text&quot;:&quot;this is a simple page, about a simple umbrella.&quot;,
                 &quot;type&quot;:&quot;text&quot;
              }
           ]
        },
        {
           &quot;type&quot;:&quot;paragraph&quot;,
           &quot;content&quot;:[
              {
                 &quot;text&quot;:&quot;you can use this text to find the umbrella page.&quot;,
                 &quot;type&quot;:&quot;text&quot;
              }
           ]
        },
        {
           &quot;type&quot;:&quot;paragraph&quot;,
           &quot;content&quot;:[
              {
                 &quot;text&quot;:&quot;do you like it?&quot;,
                 &quot;type&quot;:&quot;text&quot;
              }
           ]
        },
  </code></pre>
  <p>I know I can use <code>Object.keys</code> but that only covers the &quot;top level&quot; and doesn't go deeper.</p>
  <p>I don't wish to use recursion for this, but use an iterative function.</p>
  <p>I tried to use <code>JSON.stringify</code> but it has poor performance:</p>
  <pre><code>const obj = JSON.parse(content);
  let ret = '';
  JSON.stringify(obj, (_, nested) =&gt; {
    if (nested &amp;&amp; nested[key]) {
      ret += nested[key] + '\n';
    }
    return nested;
  });
  </code></pre>