@@ -682,11 +682,12 @@ function formatObject(ctx, value, recurseTimes, visibleKeys, keys) {
682
682
683
683
684
684
function formatArray ( ctx , value , recurseTimes , visibleKeys , keys ) {
685
+ const maxLength = Math . min ( Math . max ( 0 , ctx . maxArrayLength ) , value . length ) ;
685
686
var output = [ ] ;
686
687
let visibleLength = 0 ;
687
688
let index = 0 ;
688
689
for ( const elem of keys ) {
689
- if ( visibleLength === ctx . maxArrayLength )
690
+ if ( visibleLength === maxLength )
690
691
break ;
691
692
// Symbols might have been added to the keys
692
693
if ( typeof elem !== 'string' )
@@ -701,15 +702,15 @@ function formatArray(ctx, value, recurseTimes, visibleKeys, keys) {
701
702
const message = `<${ emptyItems } empty item${ ending } >` ;
702
703
output . push ( ctx . stylize ( message , 'undefined' ) ) ;
703
704
index = i ;
704
- if ( ++ visibleLength === ctx . maxArrayLength )
705
+ if ( ++ visibleLength === maxLength )
705
706
break ;
706
707
}
707
708
output . push ( formatProperty ( ctx , value , recurseTimes , visibleKeys ,
708
709
elem , true ) ) ;
709
710
visibleLength ++ ;
710
711
index ++ ;
711
712
}
712
- if ( index < value . length && visibleLength !== ctx . maxArrayLength ) {
713
+ if ( index < value . length && visibleLength !== maxLength ) {
713
714
const len = value . length - index ;
714
715
const ending = len > 1 ? 's' : '' ;
715
716
const message = `<${ len } empty item${ ending } >` ;
0 commit comments