JS Merging objects

Source: Internet
Author: User

Work for a long time has been no perseverance to do something. This year began to prepare all the basics. Then write some blog to facilitate their own query later.

A basic knowledge of the recent collation of JavaScript. Wrote for a long time the code found himself to now also just use the JS framework for the native JS understanding is not deep.

var merge=function (s,p) {
For (prop in s)
{
if (P.hasownproperty[prop]) continue;

P[prop]=s[prop];
}
return p;
}

var obj1={a:1,c:3};
var obj2={a:1,c:5,b:2,d:4}


Merge (OBJ1,OBJ2)

The result of the output is:

A:1

B:2

C:3

D:4

JS Merging objects

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.