title: How to store and retrieve the data from javascript function
body: <p>I am new to javascript and I want to store the data from the function. This is the function I've written.</p>
  <pre><code>function OnlyReadOneText(txt){
      var file = event.target.files[0];
      var api = new FileReader();
      api.onload = function(){
              var typedarray = new Uint8Array(this.result)
              const task = pdfjsLib.getDocument(typedarray)
              task.promise.then((pdf) =&gt;{
                  console.log(&quot;This pdf has &quot; + pdf.numPages + &quot; pages&quot;)
                  
                  var countPromises = [];  
                  for (var j = 1; j &lt;= pdf.numPages; j++) {
                      var page = pdf.getPage(j);
                      var txt = &quot;&quot;;
  
                      countPromises.push(page.then(function(page) { // add page promise
                      var textContent = page.getTextContent();
                      console.log(textContent );
  
                      return textContent.then(function(text){ // return content promise
                          return text.items.map(function (s) { 
                              return s.str; 
                          }).join(''); // value page text 
                      });
                      }));
                  }
                      // Wait for all pages and join text
                      return Promise.all(countPromises).then(function (texts) {
                          txt = texts.join(''); //&lt;---------------- I want this piece of info
                          return texts.join('');
                      });
              });
          }
          api.readAsArrayBuffer(file);  
     }
  </code></pre>
  <p>I do it in this way in javascript:</p>
  <pre><code>var ans = OnlyReadOneText();
  </code></pre>
  <p>It only return nothing no &quot;ans&quot;. How to get texts.join and shown on ans?</p>