title: Javascript - getting TypeError is not iterable for an array
body: <p>I am using react and I have a component where I am setting a constant with an array of strings:</p>
  
  <pre><code>const propsToCheck = ['text', 'type', 'status', 'topic.name', 'class.0.code'];
  </code></pre>
  
  <p>I am sending down the children chain all the way to the component that is using it like this in the function <code>checkObjectContainsValue</code> that I import from another file:</p>
  
  <pre><code>constructor(props) {
      super(props);
      this.state.data = this.transformRows(props.rows.filter(obj =&gt; checkObjectContainsValue(obj, props.searchString)(props.propsToCheck)))
    }
  </code></pre>
  
  <p>My tests are failing then because I get an error:</p>
  
  <blockquote>
    <p>TypeError: propsToCheck is not iterable</p>
  </blockquote>
  
  <p>But, I noticed that if I import the <code>checkObjectContainsValue</code> function to a parent component where I have <code>propsToCheck</code> I don't get the error. But I can't have that function there for other reasons. I have checked the react developer tools and I can see that I am getting the array <code>propsToCheck</code> in the child component, so I am not sure why I am getting this error?</p>
  
  <p>This is the function <code>checkObjectContainsValue</code>:</p>
  
  <pre><code>const checkObjectContainsValue = (obj, value) =&gt; (propsToCheck) =&gt; {
    for (let prop of propsToCheck) {
      const propToCheckValue = prop.split('.').reduce((currentObject,property) =&gt; {
        return currentObject[property];
      }, obj);
      if (propToCheckValue.toLowerCase().includes(value.toLowerCase())) {
        return true;
      }
    }
    return false;
  };
  </code></pre>
  
  <p><strong>Update</strong></p>
  
  <p>If I move the logic to a parent component then everything works fine. This is the example:</p>
  
  <pre><code>onSearchChange(event) {
      const searchString = event.target.value;
      this.setState(prevState =&gt; {
        const filteredTasks = prevState.tasks.filter(obj =&gt; checkObjectContainsValue(obj, searchString)(propsToCheck));
        return {filteredTasks: filteredTasks};
      });
    }
  </code></pre>
  
  <p>Why am I getting this error only when I use this function in the child component?</p>