Loop and iterate through key value pair from object literal - Javascript Object

Javascript examples for Object:Object Literal

Description

Loop and iterate through key value pair from object literal

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(){/*from w  ww . j  a v  a  2s .  c  o m*/
var myObj = {
  style: "test",
  origin: "Thailand",
  day: "18d",
  color: "",
  abc: "",
  def: undefined,
  weight: null
}
for(var keys in myObj){
   if(myObj[keys] ===null || myObj[keys] == ""){
       delete myObj[keys]
   }
}
console.log(myObj)
    }

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

Related Tutorials