merging array in javascript -
this question has answer here:
- merge/flatten array of arrays in javascript? 52 answers
is there way merge following array :
var arr = [["2014-2-5", "2014-2-4", "2014-1-9", "2014-1-8"], [], ["2014-2-4"], [], []]
and make :
["2014-2-5", "2014-2-4", "2014-1-9", "2014-1-8", "2014-2-4"]
i tried console.log($.merge(arr ));
not working.
thanks
use array's reduce
in combination concat
:
arr.reduce(function(previousvalue, currentvalue, index, array){ return previousvalue.concat(currentvalue); });
Comments
Post a Comment