JSFiddle - React, Tailwind, and code Playground

by Gerald Gillespie

JavaScript

const troublesome= Array(15);

//fill it up for 5.    1/4 empty; 1/4 undefined; 1/4 integers; 1/4 null
[...Array(5)].forEach((x,i)=>{   
   troublesome[i+5]=x;
   troublesome[i+10]=i;
   troublesome[i+15]=null; 
}   );



const noMoreTrouble = new Proxy(troublesome, {
    get(t,p){
      if( typeof p === 'string' && /^\d/.test(p) && !Reflect.has(t,p)) return null;
      
      if(p === 'original') return t;
      
      return Reflect.get(t,p); 
     
    }
});


//prints : 
// [null, null, null, null, null, undefined, undefined, undefined, undefined, undefined, 0, 1, 2, 3, 4,null,null,null,null,null]

console.log(noMoreTrouble);


console.log(noMoreTrouble.original);

//true
console.log(noMoreTrouble[0] === null);

//still false 
console.log(troublesome[0] === null);