I have 2 objects and combine them using a function jQuery.extend
.
john_5_years_ago = {
name: "john",
company: "google",
languages: ["c++", "java"]
}
john_now = {
name: "john",
company: "facebook",
nation: "US",
languages: ["python", "java", "javascript"]
}
$.extend(true, {}, john_5_years_ago, john_now)
It returns the result as follows:
{
name: "john",
company: "facebook",
nation: "US",
languages: ["python", "java", "javascript"]
}
But I was expecting the value of the array languages
to be combined, not to be overwritten. And the expected result should be like this:
{
name: "john",
company: "facebook",
nation: "US",
languages: ["python", "java", "javascript", "c++"]
}
I would be grateful for any ideas.
source
share