javascript - impliment array.map() on an array which itself is an element of another array -


here have array called "array" has 4 arrays element.as individual elements of "array" arrays itself,so can use array methods on them,right?so if choose first element array[0].map(callback) ,but unfortunately error occurring .how can fix problem ??

var array=[['apple','jackfruit'],['orange'],['pineapple'],['banana']]; (function(){    console.log(array[0]);      var arr=array[0].map(function(row){          return row.reduce(function(first,second){              return math.max(first,second.length);          },0);       });       console.log(arr);   })(); 

i can guess - search string in array largest length?

with http://lodash.com/ can this:

var array=[['apple','jacklongfurit'],['orange'],['pineapple'],['banana']];  // sort string.length (reverse) , use "flatten" make 1-imension-array. array = _.sortby(_.flatten(array), function(element){     return -element.length;  });  console.log(array[0]); 

Comments

Popular posts from this blog

php - Submit Form Data without Reloading page -

linux - Rails running on virtual machine in Windows -

php - $params->set Array between square bracket -