I've two objects and I want to add properties from object A to object B and I try with extend which doesn't work,do I need to use something different ?
a = {
name = "value"
name2 = "value2"
}
b = {
name3 = "value"
name4 = "value2"
}
I want that A will contain both
a = {
name = "value"
name2 = "value2"
name3 = "value"
name4 = "value2"
}
First of all, your defined objects are incorrect. Objects must be written as
name:value
pairs, separated by a colon (and not by an equality sign). Furthermore, you must use comma separators to delimit the properties of the object, like:To extend an object with various properties via lodash, you can use
_.assign(object, [sources], [customizer], [thisArg])
:I believe you want to use the lodash
merge
function, rather thanextend
. See: Lodash - difference between .extend() / .assign() and .merge()_.extend
(now called_.assign
) is indeed how you do this:Live Example: