title: array map split join, javascript
body: <p>I  need help in understanding this piece of code.
  What is it doing and what is the type its returning. Possibly break it in smaller chunks to understand.</p>
  <p>Why would it join array elements on '.' and then split them using the same dilimentor'.' What type of array is being passed back from search results?</p>
  <pre><code>    function getRandomInt(max, min = 0) {
        return Math.floor(Math.random() * (max - min + 1)) + min; // eslint-disable-line no-mixed-operators
      }
  
  const searchResult = query =&gt;
    new Array(getRandomInt(5))
      .join('.')
      .split('.')
      .map((item, idx) =&gt; {
        const category = `${query}${idx}`;
        return {
          value: category,
          label: (
            &lt;div
              style={{
                display: 'flex',
                justifyContent: 'space-between',
              }}
            &gt;
              &lt;span&gt;
                Found {query} on{' '}
                &lt;a
                  href={`https://s.taobao.com/search?q=${query}`}
                  target=&quot;_blank&quot;
                  rel=&quot;noopener noreferrer&quot;
                &gt;
                  {category}
                &lt;/a&gt;
              &lt;/span&gt;
              &lt;span&gt;{getRandomInt(200, 100)} results&lt;/span&gt;
            &lt;/div&gt;
          ),
        };
      });
  </code></pre>
  <p>its been called like this</p>
  <pre><code>const [options, setOptions] = useState&lt;SelectProps&lt;unknown&gt;[&quot;options&quot;]&gt;([]);
  
    const handleSearch = (value: string) =&gt; {
      setOptions(value ? searchResult(value) : []);
    };
  </code></pre>
  <p>I want to be able to put console.log to see what value is setOptions getting.
  Thanks</p>
  <pre><code>----------------- Update 2-----------------
  const searchResult = (query: string) =&gt; {
    const myArray = new Array(getRandomInt(5)).fill(0).map((item, idx) =&gt; {
      const category = `${query}${idx}`;
      return {
        value: category,
        label: labelElement(query, category),
      };
    });
    console.log(myArray);
    return myArray;
  };
  
  
  const labelElement = (query: string, category: string) =&gt; {
    return (
      &lt;div
        style={{
          display: &quot;flex&quot;,
          justifyContent: &quot;space-between&quot;,
        }}
      &gt;
        &lt;span&gt;
          Found {query} on &lt;a&gt;{category}&lt;/a&gt;
        &lt;/span&gt;
        &lt;span&gt;{getRandomInt(200, 100)} results&lt;/span&gt;
      &lt;/div&gt;
    );
  };
  
  const [options, setOptions] = useState&lt;SelectProps&lt;unknown&gt;[&quot;options&quot;]&gt;([]);
  
    const handleSearch = (value: string) =&gt; {
      setOptions(value ? searchResult(value) : []);
    };
  </code></pre>