Posted By

supermauerbros on 06/23/11


Tagged

object key for literal iterate


Versions (?)

Iterate through keys in an object literal and return the key name.


 / Published in: JavaScript
 

Returns the key name in mainObject if it's a key, and hasOwnProperty of key (to rule out the prototype object. Then it also checks if the key is listed in an array using a jquery function and also tests if it's null.

  1. for (var key in mainObject){
  2. if(key && mainObject.hasOwnProperty(key) && ($.inArray(key, testAgainstThisArray) !== -1 ) && mainObject[key] !== null ) {
  3. console.log(key);
  4. }
  5. }

Report this snippet  

You need to login to post a comment.