diff options
author | Zachary Ferguson <zfergus2@users.noreply.github.com> | 2015-10-15 14:48:59 -0400 |
---|---|---|
committer | Zachary Ferguson <zfergus2@users.noreply.github.com> | 2015-10-15 14:48:59 -0400 |
commit | 65bb71f4bde383a4d0b8cd6fd49901bb6e2cfa5f (patch) | |
tree | 03802f50ac31b295ace0585ccb6bc1ea6ef9b612 /javascript.html.markdown | |
parent | a4ea3961744c3c1ee6fcf654f011caa8dbadf56e (diff) | |
parent | 68953bd9d97328b8660dad06edd8acb8ff330ede (diff) |
Merge remote-tracking branch 'refs/remotes/adambard/master'
Conflicts:
c.html.markdown
Diffstat (limited to 'javascript.html.markdown')
-rw-r--r-- | javascript.html.markdown | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/javascript.html.markdown b/javascript.html.markdown index 754832f1..6ea0b0bb 100644 --- a/javascript.html.markdown +++ b/javascript.html.markdown @@ -218,6 +218,26 @@ for (var i = 0; i < 5; i++){ // will run 5 times } +//The For/In statement loops iterates over every property across the entire prototype chain +var description = ""; +var person = {fname:"Paul", lname:"Ken", age:18}; +for (var x in person){ + description += person[x] + " "; +} + +//If only want to consider properties attached to the object itself, +//and not its prototypes use hasOwnProperty() check +var description = ""; +var person = {fname:"Paul", lname:"Ken", age:18}; +for (var x in person){ + if (person.hasOwnProperty(x)){ + description += person[x] + " "; + } +} + +//for/in should not be used to iterate over an Array where the index order is important. +//There is no guarantee that for/in will return the indexes in any particular order + // && is logical and, || is logical or if (house.size == "big" && house.colour == "blue"){ house.contains = "bear"; |