javascript - Get the array with highest length from a parent array -
what best way array max length?
i have array follows,
main = [ [1,2,3], [4], [5,6,7,8], [9,0] ]
i need store array max length, in case
maxarray = main[2]
use array#reduce
method.
main = [ [1, 2, 3], [4], [5, 6, 7, 8], [9, 0] ]; console.log( main.reduce(function(a, b) { return a.length > b.length ? : b; }) );
Comments
Post a Comment