Where do we use $.extend() method in jQuery?

jQueryWeb DevelopmentFront End Technology

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 −


Live Demo

<!DOCTYPE html>

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></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);
   <button id="button1">Result</button>
   <div id="demo"></div>
Updated on 15-Jun-2020 13:18:40