Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
24
rated 0 times [  30] [ 6]  / answers: 1 / hits: 15744  / 8 Years ago, thu, may 19, 2016, 12:00:00

Let's say I have a variable users that contains the following string of text where each user is separated by a semicolon and each attribute of each users is separated by a comma:



Bob,1234,[email protected];Mark,5678,[email protected]


How would I split this into a multidimensional array variable userArray that looks like this:



[
[Bob,1234,[email protected]],
[Mark,5678,[email protected]]
]


using JavaScript?


More From » arrays

 Answers
7

You can do this with split() and map()





var str = 'Bob,1234,[email protected];Mark,5678,[email protected]';
var result = str.split(';').map(e => e.split(','));
console.log(result)



[#62099] Tuesday, May 17, 2016, 8 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
freddiem

Total Points: 456
Total Questions: 116
Total Answers: 101

Location: Dominica
Member since Mon, Jan 4, 2021
3 Years ago
;