Timeline for How can I access and process nested objects, arrays, or JSON?
Current License: CC BY-SA 4.0
7 events
when toggle format | what | by | license | comment | |
---|---|---|---|---|---|
Sep 27, 2018 at 18:03 | comment | added | reggaeguitar | @DineshPandiyan you should disclose that you're the author of typy, I just came here after reading your blog post | |
Jul 9, 2018 at 4:01 | history | edited | Dinesh Pandiyan | CC BY-SA 4.0 |
deleted 67 characters in body
|
Jul 9, 2018 at 4:01 | comment | added | Dinesh Pandiyan | This is great. It didn't strike me this way. Thank @FelixKling, I'll go update the blog posts. | |
Jul 9, 2018 at 3:49 | comment | added | Felix Kling |
You are not applying your pattern consistently. Of course ...[1].bar would result in an error if the element 1 didn't exist. But that's also the case for ....foo.bar if foo didn't exist. You have to "guard" accessing 1 as well, just like you "guard" any other property access. An array is just an object. An "array element" is just a property. Correctly applied it would be (((user || {}).address || {})[1] || {}).name .
|
|
Jul 8, 2018 at 16:20 | comment | added | Dinesh Pandiyan |
@FelixKling When we try to access arrays with Oliver Steele pattern, we won't be able to create array on 'n' length on the fly and access nth index without getting 'undefined' error. Ex. ((user || {}).address || new Array(3))[1].name
|
|
Jul 7, 2018 at 15:47 | comment | added | Felix Kling | This question is primarily about access properties that exist. There is already a question about what you are referring to (and already including most of your solutions): Access Javascript nested objects safely or Accessing nested JavaScript objects with string key. But anyway: "Unfortunately, you cannot access nested arrays with this trick." Why not? Arrays are objects, so it should work just as well. Can you provide an example where it does not? | |
Jul 7, 2018 at 8:32 | history | answered | Dinesh Pandiyan | CC BY-SA 4.0 |