Fill remaining length of array with falsy values - Javascript Array Operation

Javascript examples for Array Operation:Array Element

Description

Fill remaining length of array with falsy values

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <meta name="viewport" content="width=device-width, initial-scale=1"> 
      <script type="text/javascript">
    window.onload=function(){/*  ww w  .ja  v a 2 s  .  c  o  m*/
const d = [
  [true, true],
  [true],
  [true, true, true],
  [true]
];
r = [];
for(var n in d) {
  var k = d[n];
  if(k.length >=3) {
     r.push(k);
  } else{
     while(k.length < 3) {
       k.push(false);
    }
    r.push(k);
  }
}
console.log(r)
    }

      </script> 
   </head> 
   <body>  
   </body>
</html>

Related Tutorials