
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Use of extend Method in jQuery
The jQuery.extend() method is used to merge contents of two or more objects together. The object is merged into the first object.
You can try to run the following code to learn how to use extend() method −
Example
<!DOCTYPE html> <html> <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script> <script> $(document).ready(function() { $("#button1").click(function() { var obj1 = { maths: 60, history: {pages: 150,price: 400,lessons: 30}, science: 120 }; var obj2 = { history: { price: 150, lessons: 24 }, economics: 250 }; $.extend(true, obj1, obj2); $("#demo").append(JSON.stringify(obj1)); }); }); </script> </head> <body> <button id="button1">Result</button> <div id="demo"></div> </body> </html>
Advertisements