3
    function parser(data){
    var saveSections = data.split("\r");
    var parsed = new Array();
    var tempCatch = "";
    var CatchTwo = [];
    //saveSections[0] = saveSections[0].split(",");
    for (var i = 0; i < saveSections.length; i++){
        saveSections[i] = saveSections[i].split(",");
        for (var j = 0; j < saveSections.length; j++){
            tempCatch = saveSections[0][0].split(":");
            //saveSections[0][0] = tempCatch;

        }

    }
    return tempCatch;
}

Ok there is problem. This function works without problems until I uncomment

//saveSections[0][0] = tempCatch;.

When I do it, debbuger throws:

Uncaught TypeError: saveSections[0][0].split is not a function

That points at this line:

tempCatch = saveSections[0][0].split(":");
4
  • 1
    You've to iterate the third depth too, arrays have not split method. Commented Jul 12, 2015 at 17:03
  • But I'm spliting elemment of 2D array. It will be 3D AFTER splitting. Commented Jul 12, 2015 at 17:06
  • Could you provide a sample of the input this function gets? Commented Jul 12, 2015 at 17:09
  • It contains chars that will not be shown here. It's part of encryption algorithm. :( D:Ch,XPL:1,XPS:987654321,XPE:987654320,E:0,C:2,AC:1,P:0,G:,A:1,S:1,HC:1,H:1,SCO:1,SCR:1,K:2,B:0,BT:0,IP:94.231.225.11,ID:0,IS:1,CM:0D:Eq,I:1,T:1,L:1,C:BBAAD:Eq,I:2,T:2,L:1,C:QIAAD:In,I:25,T:7,Q:30D:Op,M:1,S:1,P:1D:SP,S:BBBBBBBB Commented Jul 12, 2015 at 17:11

1 Answer 1

1

From the sample data you gave, the problem is that you're always assigning tempCatch to the first item in the 2D array (saveSections[0][0]), at the second iteration the split() function fails because that's an array, not a string.

This code should iterate on all items:

function parser(data){
    var saveSections = data.split("\r");
    var parsed = [];
    var tempCatch = "";
    var CatchTwo = [];
    for (var i = 0; i < saveSections.length; i++){
      saveSections[i] = saveSections[i].split(",");
      for (var j = 0; j < saveSections[i].length; j++){
          tempCatch = saveSections[i][j].split(":");
          saveSections[i][j] = tempCatch;
      }
    }
    return saveSections;
}

I would assume you need to return saveSections instead of tempCatch, but that's a bit unclear from your implementation.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.