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);
}
}
asked Jul 18, 2015 at 4:13
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]);
answered Jul 18, 2015 at 4:19
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/

answered Jul 18, 2015 at 4:27

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);
}
}
answered Jul 18, 2015 at 4:39

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.