That is to make this:
[ [\'dog\',\'cat\', [\'chicken\', \'bear\'] ],[\'mouse\',\'horse\'] ]
into:
[\'dog\',\'cat\',\'chicken\',\'
Grab underscore.js and use the flatten function.
_.flatten([ ['dog','cat', ['chicken', 'bear'] ],['mouse','horse'] ]);