![]() |
Split a string into an 2 d array of substrings:
Hi Guys,
I want to split a string into a 2 d array of substrings like the following : string = " id1,name1,id2,name2,id3,name3...." array element [0][0] = id1 element [0][1] = name1 element [1][0] = id2 element [1][1] = name2 ...etc i tried to tweak the JavaScript split() Method but no result. Any help ? thanks |
Well, the obvious:
Code:
var s = "id1,name1,id2,name2,id3,name3...."Code:
var s = "id1,name1,id2,name2,id3,name3...."Seems hardly worth trouble. I'd just use version 1. |
Thanks man.
I will try this. |
To 'OldPedant':
Please pardon the interruption. I have been experimenting with you script of post #2. I easily figured out how to expand it to 3 (or more) elements within the array. Very helpful. However, to test my understanding of the DOM nomemclature, I tried to expand it to use named elements, which you can find in the 3rd (non-working) attempt below. The error I'm getting is that "TypeError: rec is not a constructor" I've tried some variations on the code, but without success. Could you tell me the correct syntax to use to make it a constructor? Thank you for any time invested into my question. Code:
<!DOCTYPE html> |
jmrker: this should fix your problem
Code:
var rec =function(){return { id:'', name:'', state:'', phone:'' }; }; |
And another fix
str += elem[i].id+','+elem[i].name+','+elem[i].state+','+elem[i].phone+'<br>'; |
Quote:
Quote:
|
| All times are GMT +1. The time now is 11:45 PM. |
Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.