Loop error in Text Compression (indexing words)

Im trying to make a script that compresses a certain text, by replacing often used words with an index number. I also want to optimize it by looking at the number of times a certain word is used. The code below is just a starting point, trying to test if a word from the text_array is in the (final) Index Array. If not i should be added, if it is already in there the count should go up with 1. Sounds simple ey? well i managed to screw it up… I get way to much entries in my Index, so i must be overlooking something… any help?

text1="test1 test2 test3 test1 test1 test3 test1 test2";

tempArray=text1.split(" ");

var Index = new Array();
Index = [ ["word",1]]

for (i=0;i<tempArray.length;i++){g=1;
    for (j=0;j<Index.length;j++){
        if (tempArray*!=Index[j][0]) {