Last active
February 4, 2017 16:08
-
-
Save theCrab/d9cb8a0fcd931512c0c27502749e8da9 to your computer and use it in GitHub Desktop.
Ola's Loop
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var array = [] | |
var emptyValuesArray = [] | |
var hash = { a: 1, b: 1, c: 1, d: 1, e: null, f: null } | |
forEach( h in hash) { | |
// Loop through each element inside the hash variable above | |
// if the value is null or empty ('') i.e true, | |
// add the h to the array, if false add to emptyValuesArray | |
if (h.value === null || ha.value === '') { // Check if h.value is empty or null. Returns true/false | |
array.push(h) | |
}else { | |
emptyValuesArray.push(h) | |
} | |
} | |
// hash.key and hash.value | |
print(hash['a'].key) // a | |
print(hash[0].key) // a | |
print(hash['a'].value) // 1 | |
print(hash[0].value) // 1 | |
// array | |
print(array) // [a: 1, b: 1, c: 1, d: 1] | |
print(emptyValuesArray) // [ e: null, f: null ] | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment