0

My script (is meant to) grab text from the a page (which works fine) and then splits it by by newline (\n) and puts each splitted string into an array called "dnaSequence"; from there it loops through each element in the array and if the string contains the character ">" it assigns that string to the "var header_name", else it pushes all other lines into a new array called "dnaSubseq". The original text looks something like this:

>header_1
gctagctagc
cgcgagcgagc
>header_2
gcgcatgcgac

When I execute the code it fails to alert on anything. Here is the code:

function loaderMy() {

var dnaSubseq = [];
var dnaSequence = [];
var header_name = "";
var splittedLines = document.getElementById("page-wrapper").innerText;
dnaSequence = splittedLines.split('\n');

for (var i = 0; i < dnaSequence.length; i++) {
    if (dnaSequence[i].match(/>/)) {
        header_name = dnaSequence[i];
        alert(header_name);
    }
    else {
        dnaSubseq.pushValues(dnaSequence[i]);
    }
    alert(dnaSubseq);
}
}
1
  • 3
    push not pushValues Commented Jul 18, 2015 at 4:17

3 Answers 3

1

Change

dnaSubseq.pushValues(dnaSequence[i]);

To

dnaSubseq.push(dnaSequence[i]);
Sign up to request clarification or add additional context in comments.

Comments

0

If it doesn't alert anything, that means you forgot to invoke the function :)

loaderMy();

http://jsfiddle.net/zszyg5qx/

Comments

0

Try this function

function loaderMy() {
    var dnaSubseq = [];
    var dnaSequence = [];
    var header_name = "";
    var splittedLines = document.getElementById("page-wrapper").innerText;
    dnaSequence = splittedLines.split('\n');

    for (var i = 0; i < dnaSequence.length; i++) {
        if (dnaSequence[i].match(/>/)) {
            header_name = dnaSequence[i];
            alert(header_name);
       }
       else {
               dnaSubseq.push(dnaSequence[i]);
       }
  alert(dnaSubseq);
}
}

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.