javascript - How to find the largest length for every column in a huge multidimensional Array -
We have this type of array and indicate the length of the word in the maximum column.
Miscellaneous data = [["1111", "44"], ["222", "55555"], ["33", "666"], ...]; "1111". Long & gt; "222". Long & gt; "33". Length, "55555" Long & gt; "666". Long & gt; "44". Length max max - & gt; [4,5];
Because this array is really huge, what would be the most effective way to do this?
var data = [['ABC', 'ABCD', 'ABCDEF', ' ABCD, ABC, ABCDF, ABC, ABC 'ABC', 'ABCDF', 'ABC', 'AB', 'ABCDF', 'ABCD', 'ABC', ' ABC ', [' ABCDF ',' ABC ',' ABC '' ABCDEFG ',' ABC ',' A ',' ABCDEF ',' ABCD ',' AB ',' ABC ']]; Var _maxs = []; Var leghtoffre = data [0]. Length, _max = []; (Var i = 0; i & lt; lenghtOfRow; i ++) _maxs.push (0); Data.forEach (function (record) {record.forEach (function (VL, Indx) {if (vl.length & gt; _maxs [indx]) _maxs [indx] = vl.length;})}); Console.log (_maxs);
Is there any more effective way?
Renewed:
_maxs = []; Data.forEach (function (record) (record.forEach (work (VL, Indx) {if (vl.length & gt; (_maxs [indx] || 0)) _maxs [indx] = vl.length;})} );
Comments
Post a Comment