Jquery Extend Example - Jquery

How to merge the contents of two or more objects together in extend method?

Snippet Code


  
Rate this page :
  [ 0 votes]

Jquery $.extend() method is used to combine the contents of more than two objects into the content of first object. The simple code using extend method is given below.

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script> <script type='text/javascript'> var demo_obj1 = { orange: 0, banana: { weight: 52, price: 100 }, cherry: 97 }; var demo_obj2 = { banana: { price: 200 }, mango: 100 }; var extended = $.extend(demo_obj1, demo_obj2); console.log(JSON.stringify(extended)); </script>

Tags


Ask Questions

Ask Question