Created
August 10, 2018 13:56
-
-
Save ldmarz/17511adf1a1b89edb4fca5426c4e69af to your computer and use it in GitHub Desktop.
Set and Get lodash example
This file contains 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 someNiceObject = { hello: { someDeepKey: "hello" } }; | |
_.set(someNiceObject, "hello.items[0]", "An item"); | |
// here items was added safely | |
// someNiceObject === { hello: { someDeepKey: "hello", items: ["An item"] } } | |
//Here we can access to a not existing key getting a default value instead | |
var name = _.get(someNiceObject, "someNotExistingKey", "Ldmarz"); | |
// name => Ldmarz |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment