Thursday, 15 August 2013

How do I take a JS array that has some elements that are also arrays and make ALL array elements top level elements

How do I take a JS array that has some elements that are also arrays and
make ALL array elements top level elements

I'm sorry if this has been asked, I'm not even sure how best to phrase the
question, so I'll do it in code. Note: I have no control over the source
format of the data, so I have to work with it as is...
I have an array that looks like this (the real thing has many entries,
hundreds, all mixed like this, with some of the elements being comma
separated values others not):
var array = ["item1", "item2", "item3, item4", "item5", "item6"]
I already know how to make it like this:
var array = ["item1", "item2", ["item3", "item4"] , "item5", "item6"]
What I need is for it to be like this:
var array = ["item1", "item2", "item3", "item4", "item5", "item6"]
This project uses jQuery 1.7 and the point is to take a static list of
data and parse it into a single array for use in the jQuery UI
Autocomplete plugin. Again, I have no control over the format of the
keywords (which is what these are) being passed to the client, the
application does what it does, I can only work with the client-side code
(gotta love compartmentalization, huh?)

No comments:

Post a Comment