Jump to content
MakeWebGames

split variable


mikemastah

Recommended Posts

Re: split variable

looks like what I need but I need some help to use it I'm afraid.

At this time I have a var 'mrnaCodes' which is the value of an input field.

I used to do this "var mrnaArray = mrnaCodes.split(" ");" for the input with spaces (ex1)

 

BLA BLA BLA BLA BLA

but now I want them able to choose between ex1 and ex2.

 

BLABLABLABLABLA

I do need however the same array

mrnaArray[0]="BLA"

mrnaArray[2]="BLA" etc.

Link to comment
Share on other sites

Re: split variable

ah, figured it out.

/*User input*/
var mrnaCodes = "AAAUUUCCCGGGAAAUUUCCCGGGGGGCCCUUUAAA";

function someThing(); {
var startSlice = 0;
var mrnaArray=new Array();

 while(startSlice<mrnaCodes.length) { 
   endSlice = startSlice+3;
   var i=startSlice/3;
   mrnaArray[i] = mrnaCodes.slice(startSlice,endSlice);
   startSlice = startSlice+3;
   }
}

 

thanks for the help

Link to comment
Share on other sites

Re: split variable

You're welcome for the help, and glad that worked for ya.

Yes, that's exactly how to do that, good job ;)

One suggestion: To automatically tell javascript to add an element to the end of an array (similar to PHP's method: $array[] = $next), use this:

mrnaArray[mrnaArray.length]

This will only work with numeric arrays, of course.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...