How to create a dictionary, using as a keys the frequency of the words?
<p>I am writing a script I would like to create a dictionary with some array's words, the array is called removeArray and looks as follows:</p>

<pre><code>["RBD", "X", "RBD3", "C", "92173", "GJHGWO.NAYE", "SAMBORNSiPOSSSTHRa1", "GJHGX4.NAYE", "SAMBORNSiPOSSSTHRa", "X3", "GJHGX6.NAYE", "GJHGX8.NAYE", "SAMBORNSiPOSSSTHRa2", "GJHGXA.NAYE", "GJHGXC.NAYE"]
</code></pre>

<p>I extracted that words from a text area, that looks like this:</p>

<pre><code>"RBD|X|RBD3|C|92173~GJHGWO.NAYE" "SAMBORNSiPOSSSTHRa1"
"RBD|X|RBD|C|92173~GJHGX4.NAYE" "SAMBORNSiPOSSSTHRa"
"RBD|X3|RBD3|C|92173~GJHGX6.NAYE" "SAMBORNSiPOSSSTHRa1"
"RBD|X|RBD|C|92173~GJHGX8.NAYE" "SAMBORNSiPOSSSTHRa2"
"RBD|X|RBD|C|92173~GJHGXA.NAYE" "SAMBORNSiPOSSSTHRa2"
"RBD|X3|RBD|C|92173~GJHGXC.NAYE" "SAMBORNSiPOSSSTHRa"
</code></pre>

<p>I would like to create a dictionary that would be composed as the following way, first the keys are the words contained in the array called removeArray, and the value of the dictionary would be the frequency of this word in the textarea, The first key is "RBD" and then it´s frequency is 10, since that word appears 10 times in the textarea.</p>

<pre><code>myDictionary = { "RBD" : 10, X: 4, 92173: 6, ...}; 
</code></pre>

<p>The first key is "RBD" and then it´s frequency is 10, since that word appears 10 times in the text area.
In order to achieve this, I tried extracting first the words without repetition as follows:</p>

<pre><code>var splitWords = document.getElementById("texto").value.split(/[["\|~]/);
splitWords = document.getElementById("texto").value.split(/[["\|~]/)
uniqueWords = _.uniq(splitWords);
console.log(uniqueWords);
var removeArray  = _.remove(uniqueWords, function (word) {return word !== '' &amp;&amp; word !== ' ' &amp;&amp; word !== '\n'});
</code></pre>

<p>but then I don't know hot to convert this array into a dictionary with the specifications of above, I would like to appreciate support with this, my complete code look as follows:</p>

<pre><code>&lt;!DOCTYPE html&gt;
&lt;html&gt;
&lt;script src="lodash.js"&gt;&lt;/script&gt; 
&lt;body&gt;
&lt;p id="demo"&gt;&lt;/p&gt;
&lt;textarea cols=150 rows=15 id="texto"&gt;
"RBD|X|RBD3|C|92173~GJHGWO.NAYE" "SAMBORNSiPOSSSTHRa1"
"RBD|X|RBD|C|92173~GJHGX4.NAYE" "SAMBORNSiPOSSSTHRa"
"RBD|X3|RBD3|C|92173~GJHGX6.NAYE" "SAMBORNSiPOSSSTHRa1"
"RBD|X|RBD|C|92173~GJHGX8.NAYE" "SAMBORNSiPOSSSTHRa2"
"RBD|X|RBD|C|92173~GJHGXA.NAYE" "SAMBORNSiPOSSSTHRa2"
"RBD|X3|RBD|C|92173~GJHGXC.NAYE" "SAMBORNSiPOSSSTHRa"
&lt;/textarea&gt;
&lt;script&gt;
var splitWords = document.getElementById("texto").value.split(/[["\|~]/);
splitWords = document.getElementById("texto").value.split(/[["\|~]/)
uniqueWords = _.uniq(splitWords);
console.log(uniqueWords);
var removeArray  = _.remove(uniqueWords, function (word) {return word !== '' &amp;&amp; word !== ' ' &amp;&amp; word !== '\n'});
console.log(removeArray);
&lt;/script&gt;
&lt;/body&gt;
&lt;/html&gt;
</code></pre>