How do I use Javascript to perform a string split and access the values of an Array?

Change this line: document. Write(z + ""); to document. Write(xz + "").

Wow, that worked, thanks very much for that – iwant_B_smrtr Nov 23 at 21:27.

You don't need to set so many variables. You can split and iterate on the returned array. Str.

Split("|"). ForEach(function(i){ document. Write(i+""); }).

1 I like how forEach will cut the need for the array with index, but I do like to have one variable to collect the Array. It feel more readable to me. – natedavisolds Nov 23 at 21:36 Right, but isn't that JQuery?

I am not allowed to use that. – iwant_B_smrtr Nov 23 at 21:38 It's a 1.6 method, missing from IE8 and earlier; you can added it to the Array prototype if needed (I do). Developer.mozilla.Org/en/JavaScript/Reference/Global_Objects/… – jmulligan Nov 23 at 21:39 @jmulligan - is that jQuery?

JQuery uses each, doesn't it? Where does forEach come from? – Adam Rackis Nov 23 at 21:40 I'm not sure if it originated in jQuery; I was focused on other languages when JavaScript 1.6 was released.

It's native in any modern browser and can be shimmed into older ones. – jmulligan Nov 23 at 21:42.

Your for loop is giving you the indexes of your array, not the actual values. Change it to: for (z in x) { document. Write(xz + ""); } Or just use an old fashioned for loop: for(var I = 0; I Length; i++) { document.

Write(xi + ""); }.

Both of these answers are correct, I just wanted to add that split() returns an Array so you don't need to add another. Var str = "matt. Williams:STRING:ClassWork|1902122:STRING:AskAFriend"; var m = str.

Split("|"); for (z in m) { document. Write(mz + ""); }.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions