Right Way to Copy Objects and Arrays | Deep Vs Shallow Copy | The Complete JavaScript Course | Ep.23

Поділитися
Вставка
  • Опубліковано 18 гру 2024

КОМЕНТАРІ • 148

  • @GauthamHC99
    @GauthamHC99 Рік тому +19

    Amazing!! Everyone say that an object is referred to by a memory address but no one showed it. You are showing it and also how it is happening in browser.
    Now this makes more sense and also easy to remember.
    And @40.00 you showed how one object is stored in another object, that blew my mind, it was so simple.
    Thanks for sharing the knowledge.

    • @procodrr
      @procodrr  Рік тому +3

      Awesome bro, I'm glad that you're learning so much.
      Keep Learning and Sharing 😊

  • @mukeshsahu9399
    @mukeshsahu9399 7 місяців тому +11

    By using Json we can make deepcopy let's understand through an example:
    const ingredientsList = ["noodles", { list: ["eggs", "flour", "water"] }];
    const ingredientsListDeepCopy = JSON.parse(JSON.stringify(ingredientsList));
    JSON.stringf() converts the original element of an array into strings and then JSON.parse converts the strings elements into Object / Array by doing this the address of original array will change and this time we'll get deep copy of previous object / Array not shallow copy.
    may be I'm not able to make more clear to you. For more clarity you can see mdn.
    Thankyou Anurag sir for this Wonderful playlist.

    • @sahajranipa
      @sahajranipa 4 місяці тому

      Bro You can use structuredClone() method for deep cloning or use the lodash function for deep cloning.

  • @gurusacademy2021
    @gurusacademy2021 2 місяці тому +1

    ye naye jamane ke codrr hai..... andar tak ghus kar samjhayenge.....
    Awesome .....❣❣

  • @Swati.7819
    @Swati.7819 7 місяців тому +6

    const user1 = {
    firstName:'Anurag',
    lastName: 'Sharma',
    pata : {
    city: 'Delhi',
    pincode: 123456
    },
    subject: ['CS', 'DS', 'CN']
    }
    const user2 = JSON.parse(JSON.stringify(user1))
    This will make it Deep copy!
    Thankyou so much Sir.

  • @SatisfiedOfficial
    @SatisfiedOfficial 9 місяців тому +7

    This channel is underrated 👏❤, Great information Sir!

    • @procodrr
      @procodrr  9 місяців тому +2

      Awesome, keep learning and sharing 😊

  • @alianufo5016
    @alianufo5016 2 місяці тому +1

    WOW sir, Shallow copy Bahut Ache se samaj Agya Muje😁🤩🙏

  • @foodietravellersumit2278
    @foodietravellersumit2278 3 місяці тому +2

    Thank you so much, Sir, for sharing your excellent knowledge with us. Every day, I watch 5-6 of your JavaScript videos and practice regularly. A few days ago, I was looking for the best JavaScript tutorials on UA-cam and luckily found your channel. Once again, thank you so much. I hope one day I will become a good developer.

    • @procodrr
      @procodrr  3 місяці тому +1

      Awesome, keep learning and growing 😊

  • @hetalchauhan6486
    @hetalchauhan6486 8 місяців тому +2

    Great information sir thank you.

  • @souvikroy622
    @souvikroy622 7 місяців тому +2

    Episode 23 completed 😊 excellent video sir, bohot kuch janne ko mila. Thank you so much ❤

  • @tick4tech964
    @tick4tech964 7 місяців тому +4

    Anurag Sir OP in the chat
    Hat's off to you
    Excellent teaching 💥💥💥

  • @Walkwithmehreen
    @Walkwithmehreen 5 місяців тому +1

    bht ache se explain kie hein. core concepts strong ho rhe hein mere. keep up the good work

  • @chetandewalkar4542
    @chetandewalkar4542 9 місяців тому +3

    Great video sir🙏

  • @adityapratap7794
    @adityapratap7794 Місяць тому +1

    Learning a lot from you! Thanks! 🌟

    • @procodrr
      @procodrr  Місяць тому +1

      Keep learning and growing! 😊

  • @sanjana_2324
    @sanjana_2324 4 місяці тому +1

    Seriously hats off to u sir for providing that deep level explanation with visuals..❤

  • @Collecting_one_piece_fan
    @Collecting_one_piece_fan 2 місяці тому

    Day 10: video 24 completed thank you sir making such great video😊

  • @vinaypatil8009
    @vinaypatil8009 2 роки тому +3

    Thanks for this awesome lecture ☺️

    • @procodrr
      @procodrr  2 роки тому +2

      Welcome Bro 😊

  • @sachithkasa3811
    @sachithkasa3811 3 місяці тому

    Sir thank you sir I'm learning JavaScript from this playlist.. And it is helping me a lot because I'm in internship and I'm learning js from here❤..thank you a lot sir...

  • @Hospitality-c8z
    @Hospitality-c8z День тому

    27:38 Object.assign must be start with capital O.

  • @aditya_raj09
    @aditya_raj09 8 місяців тому +1

    Sir i am following your js course and saini sir grt work 🎉❤

  • @abhikarengegaming
    @abhikarengegaming 4 місяці тому

    Thank you for making this Series ❤

  • @henilkakadiya9565
    @henilkakadiya9565 3 дні тому

    using 1) JSON.parse(JSON.stringify(variable name)) 2)structuredClone(variable name)

  • @prathameshmohite4700
    @prathameshmohite4700 10 місяців тому +1

    Great Video Sir🔥

  • @Zaidkhan-q8o
    @Zaidkhan-q8o 5 місяців тому

    ThankYou so much sir for sharing your deep knowledge.🥰🥰

  • @venkeeshtulabandula7708
    @venkeeshtulabandula7708 5 місяців тому +1

    Sir seriously you are amazing Thankyou for sharing and seriously if i would found your channel eair then my 50000 would be saved yaar

    • @procodrr
      @procodrr  5 місяців тому

      Koi baat nahi, now that you've found it, learn well. All the best 👍

  • @MuhammadKhan-jf3kh
    @MuhammadKhan-jf3kh 2 місяці тому +1

    sir thank you so much, i love you hogaya

  • @arzoo3094
    @arzoo3094 2 місяці тому

    DeepCopy
    Const obj1 = {
    fName: 'Arzoo',
    lName:'Duddy',
    moreInfo:{
    City: 'Gurgaon',
    Pincode: 123456,
    },
    Const newObj = JSON.parse(JSON.stringify(ojb1)) 50:05

  • @anirudhdas
    @anirudhdas 6 місяців тому +3

    let user2 = JSON.parse(JSON.stringify(user1))

  • @SALUJAPAITAL
    @SALUJAPAITAL 10 місяців тому +1

    sir e chapter ekdum mast he

    • @procodrr
      @procodrr  10 місяців тому

      Awesome, keep learning and sharing 😊

  • @pranabdas3691
    @pranabdas3691 9 місяців тому +1

    first option will be the 'for loop' and second option will be JSON.parse(JSON.stringify());

  • @jatinsingh-kj9rh
    @jatinsingh-kj9rh 4 місяці тому

    Ek number bhai

  • @Onemanfive
    @Onemanfive Місяць тому

    let originalArray = [{a: 1}, {b: 2}, {c: 3}];
    let deepCopy = JSON.parse(JSON.stringify(originalArray));
    // Modifying a nested object in the deep copy
    deepCopy[0].a = 10;
    console.log(originalArray); // Output: [{a: 1}, {b: 2}, {c: 3}]
    console.log(deepCopy); // Output: [{a: 10}, {b: 2}, {c: 3}]

  • @targetindianarmy7034
    @targetindianarmy7034 6 місяців тому

    Very interesting video thanks

  • @NG95010
    @NG95010 8 місяців тому +1

    Sir aap kon sa extension use karte ho

  • @hamayunnadeem1560
    @hamayunnadeem1560 3 місяці тому

    const originalArray = [1, 2, { a: 3, b: { c: 4 } }];
    const deepCopy = structuredClone(originalArray);
    deepCopy[2].b.c = 10;
    console.log(originalArray[2].b.c); // 4 (remains unchanged)
    console.log(deepCopy[2].b.c); // 10 (changed in the deep copy)

  • @nobody20022
    @nobody20022 7 місяців тому +5

    Summary:
    Data types are based on memory allocation.
    1) Stack Memory 2) Heap Memory
    1) Stack Memory: Primitive datatype is call by Value. So in Stack Memory we get copy of the value that is why we can change it.
    2) Heap Memory: Non-Primitive datatypes is call by reference. So in heap memory we get direct reference of the that value so we are changing the reference value.
    Note: non-primitive is object. also array.
    Deep copy Answer : const user2 = JSON.parse(JSON.stringify(user1));
    Because a deep copy shares no references with its source object, any changes made to the deep copy do not affect the source object.
    new way: const user2 = structuredClone(user1);
    Because JSON.stringify() can not handle every type that we use in javascript. That is why this was introduced.
    correct me if i am wrong.

    • @blackopss017
      @blackopss017 5 місяців тому

      does strructuredClone() method clones object methods as well?

    • @nobody20022
      @nobody20022 5 місяців тому

      No, structuredClone() can not clone the function or methods if object contains methods.
      And also DOM Nodes and Symbol properties can not be cloned by this method.

    • @blackopss017
      @blackopss017 5 місяців тому

      @@nobody20022 I just chatgpt it and it says it can clone all kind of complex data including function. May be they updated the functionality of this method. But thanx for suggesting this method, it is really helpful rather than writing that json.parse and json.stringify syntax.
      There is one more method comes with lodash library called _.clonedeep()...It is works for all kind of data.

    • @blackopss017
      @blackopss017 5 місяців тому

      @@nobody20022 I just chatGpt it, and it says that this method can handle all kinda of complex data including function. This is may be because of new update to the method.
      But there is another library function called ._cloneDeep() come with lodash library which can also handle all kinds of complex data.
      Thanx for the info about structuredClone() btw.

  • @smrititripathi3091
    @smrititripathi3091 3 місяці тому

    We can deep copy any object or array using JSON.stringify() and JSON.parse() method ...
    First we will serialize the given nested object or array using JSON.stringify() method which will convert the whole object/array into a string and hence will give a totally different address to this string
    Then we will deserialize this string using JSON.parse() method which will convert the string back into object/array with completely new address for both the main object/array and also a new address for the nested object/array
    And hence any changes made to the nested object/array will not be reflected in the original one having different addresses/references

  • @shubhammane2077
    @shubhammane2077 10 місяців тому +2

    amazing

  • @asadaliasghar1094
    @asadaliasghar1094 23 години тому

    Deep Copy
    const user1DeepCopy = JSON.parse(JSON.stringify(user1))

  • @singhkr
    @singhkr 5 місяців тому +1

    sir i just want to know how do you know things in such depth ,its really awesome .please tell me how we can learn anything in such depth ,means I know how it work but I want to know what it used behind the scene.

    • @procodrr
      @procodrr  5 місяців тому

      Explore the DevTools you'll get to learn lots of new things.

  • @Bdjsisbsjsj
    @Bdjsisbsjsj 4 місяці тому

    Const user2 = JSON.parse(JSON.stringify(user1))

  • @sahajranipa
    @sahajranipa 4 місяці тому

    If we can assign an array to another array like objects using the assign() method can we use the same method for functions if yes what the use cases??

  • @risingstarks001
    @risingstarks001 8 місяців тому +1

    waiting for more interviews

  • @krishnavamsi1126
    @krishnavamsi1126 7 днів тому

    dhanyvad

  • @भोजपरीजनता-xu6bz

    const numbers = [1, [2], [3, [4]], 5]; // Using JavaScript JSON.parse(JSON.stringify(numbers)); // Using Lodash _.cloneDeep(numbers);
    JSON.stringify/parse only work with Number and String and Object literal without function or Symbol properties.
    deepClone work with all types, function and Symbol are copied by reference.

    • @procodrr
      @procodrr  Рік тому +5

      That's correct, now there is a new built-in function in JavaScript called structuredClone()
      If you pass any object inside this function it will make a deep copy and return the new object.
      And this function is available globally.

    • @officialsunnyroy
      @officialsunnyroy 9 місяців тому

      @procodrr : The web API structuredClone() also creates deep copies and has the advantage of allowing transferable objects in the source to be transferred to the new copy, rather than just cloned. It also handles more data types, such as Error. But note that structuredClone() isn't a feature of the JavaScript language itself - instead it's a feature of browsers and other JavaScript hosts that implement web APIs. And calling structuredClone() to clone a non-serializable object will fail in the same way that calling JSON.stringify() to serialize it will fail.

  • @mucatcode3468
    @mucatcode3468 8 місяців тому +1

    great work brother. I have doubt how can I search strings or Find Strings in DEV tools ?

  • @jaysanghavi7024
    @jaysanghavi7024 Рік тому +1

    Hello sir. This is correct...)
    const user2 = JSON.parse(JSON.stringify(user1));

    • @procodrr
      @procodrr  Рік тому +2

      Yes, that is correct.

  • @Manav_patel1
    @Manav_patel1 9 місяців тому +1

    Shallow Means, We Copy Values of an Object at Single Level Deep . ( Sir This Much Definition Okay For Interview ? )

  • @anujjha4421
    @anujjha4421 7 місяців тому

    Answer of Deep copy
    const person = {
    name : 'Don',
    hoobies :[
    "Web development",
    "Cricket",
    ]
    }
    const perosonecloned = structuredClone(person)

  • @vickyworld5631
    @vickyworld5631 6 місяців тому

    thankyou guruji

  • @SatyamSingh-rp3by
    @SatyamSingh-rp3by 8 місяців тому +1

    Anurag bhaiya for performing Deep Copy
    if we have an User object created like you metioned in the video then we can perform deep copy as below
    const user3 = JSON.parse(JSON.stringify(user));
    We pass the variable which we want to clone inside JSON.stringify method.

  • @ayanyadav7552
    @ayanyadav7552 5 місяців тому

    As it seen in the snapshot even the address of the immediate key-value pair such as firstName and lastName have the same address in both the objects but changing one of them is not reflecting in the other one(in Shallow copying). Can someone explain it ?

  • @ankitnauriyal6214
    @ankitnauriyal6214 4 місяці тому

    let user2 = JSON.parse(JSON.stringify(user1))
    here stringify will convert it into a string and parse will again convert back to normal code so now this code is not associated with any memory address am I right?

  • @khojeraaz
    @khojeraaz Місяць тому

    😘best way is (structuredClone(variableName)
    const user1 = {};
    let user2 = structuredClone(user1);😏

  • @indianstravellers
    @indianstravellers 8 місяців тому +1

    Amazing

  • @codewithjayant080
    @codewithjayant080 5 місяців тому

    using shallow copy it copy only the outer array or objects , if array or object contains nested array or object then it shared for both old and new array

  • @roshanprajapat-t9j
    @roshanprajapat-t9j 8 місяців тому

    const obj3 = { a: 0, b: { c: 0 } };
    const obj4 = structuredClone(obj3);
    obj3.a = 4;
    obj3.b.c = 4;
    console.log(obj4); // { a: 0, b: { c: 0 } }

  • @sameerbaral5250
    @sameerbaral5250 18 днів тому

    Bhaiya array behind the scenes object kaise hai isko bataiye thoda? Object me to key value ki tarah store hota hai array me to aisa nahi hota to behind the scenes object kaise hua plz explain kariye isko?

  • @swastikjainsj
    @swastikjainsj Місяць тому

    Structuredclone(obj)

  • @namitadas5194
    @namitadas5194 9 місяців тому

    Sir in case of string & number pass by value and objects and arrays passed by reference. Because objects are pointing to same address when one object changes another changes. In case of number it is pass by value not by reference

    • @karansharma-wn1qz
      @karansharma-wn1qz 8 місяців тому

      the reference to an object is in itself a value,

  • @shivendrarathour9483
    @shivendrarathour9483 10 місяців тому +1

    Sir jo app ye search karte ho memory devtools me searchbaar kaise ata h humara nahi ata h jaise app ne anurag and mango search kiya

    • @procodrr
      @procodrr  10 місяців тому

      Ctrl + F press karo, aa jayega.

  • @_sarthakmisal
    @_sarthakmisal 11 місяців тому +1

    Bhai agar memory allocation ignore Kara Jaye toh aage Jake koi dikkat dega kya

    • @procodrr
      @procodrr  11 місяців тому

      Haa, memory leak ho sakta hai.

  • @Onemanfive
    @Onemanfive Місяць тому

    deepCopy = JSON.parse(JSON.stringify

  • @SaveAndGrowwww
    @SaveAndGrowwww 9 місяців тому +1

    in which video you explain deep copy concept?

    • @procodrr
      @procodrr  9 місяців тому +1

      I have not explained how to do deep copy it in a separate video.
      I have explained that the concept that what is deep copy in this video itself.
      It is not you assignment to find out how can we do deep copy.

    • @SaveAndGrowwww
      @SaveAndGrowwww 9 місяців тому

      Sir, I can find it on internet (deep copy), But your explanation is wonderful. Hence, I am looking for your video about deep copy. Thankyou sir for your reply.

  • @premmourya7060
    @premmourya7060 6 місяців тому +1

    const obj1 = {
    name: "prem",
    age: 20,
    address: {
    city: "jaipur",
    pincode: 123,
    },
    };
    const obj2 = { ...obj1 }; // shalow copy
    const obj2 = { ...obj1, address: { ...obj1.address } }; // deep copy
    is s obj1 k nested obj p koi effect nhi hua, is it a good example sir ??????

    • @procodrr
      @procodrr  6 місяців тому +1

      Correct 💯

  • @Kausar-khan-q8d
    @Kausar-khan-q8d 2 місяці тому

    Please sir learn recursion in js

  • @Sar_mad_Chandia_
    @Sar_mad_Chandia_ 8 місяців тому +1

    Sir your info is very understanding... But in a video uh don't tell us how to search string in a snapshot . We cannot find option of search

    • @procodrr
      @procodrr  8 місяців тому +1

      Press Ctrl + F

  • @amardeepsingh2168
    @amardeepsingh2168 9 місяців тому

    Cont user1 = JSON.parse(JSON.stringify(user1);

  • @relightgaming7155
    @relightgaming7155 8 місяців тому +1

    sir unable to find array in system/context

    • @procodrr
      @procodrr  8 місяців тому +1

      ua-cam.com/video/Gqlv6inCZqI/v-deo.htmlsi=d0D6N-jwT6RLQkYq
      Did you watch this video?

    • @relightgaming7155
      @relightgaming7155 8 місяців тому +1

      ​@@procodrryes now I'm able to find array objects strings in system/context thankyou very much sir ❤❤

  • @pawantiwari8570
    @pawantiwari8570 7 місяців тому

    Const newObj = JSON.parse(JSON.stringify(myObj)

  • @developer_dhanji
    @developer_dhanji 9 місяців тому +1

    object copy by reference || reference type value hota hai

  • @ShailendraSingh-lb3gu
    @ShailendraSingh-lb3gu 8 місяців тому

    nice

  • @nitingujar7938
    @nitingujar7938 10 місяців тому +1

    core video

  • @shivendrarathour9483
    @shivendrarathour9483 10 місяців тому +1

    mil gya ctrl +f

    • @procodrr
      @procodrr  10 місяців тому

      Awesome 👍

  • @amanyadav7526
    @amanyadav7526 2 роки тому +2

    Sir, Git par bhi tutorial bana do 🙏🏼

    • @procodrr
      @procodrr  2 роки тому +4

      JavaScript ke baad banayenge

    • @sanchaymansinghka8917
      @sanchaymansinghka8917 2 роки тому +1

      @@procodrr sir git ka use kha pr h .

    • @procodrr
      @procodrr  2 роки тому +2

      Apne bade codebase ko manage karne ke liye golit ka use karte hain

    • @sanchaymansinghka8917
      @sanchaymansinghka8917 2 роки тому +1

      @@procodrr acha kitne din ka course h

    • @procodrr
      @procodrr  2 роки тому

      Six months, lekin tum isko 4 months mein bhi khatam kar sakte ho jab sare lectures record ho jayenge

  • @ANUBHAV_07246
    @ANUBHAV_07246 3 місяці тому

    Deep Copy
    import json
    import copy
    # Example JSON object
    original_json = {
    "name": "Alice",
    "age": 30,
    "address": {
    "street": "123 Main St",
    "city": "Wonderland"
    },
    "hobbies": ["reading", "chess"]
    }
    # Deep copy using the copy module
    deep_copied_json = copy.deepcopy(original_json)
    # Modify the deep copied object
    deep_copied_json['name'] = "Bob"
    deep_copied_json['address']['city'] = "Neverland"
    # Output the original and modified JSON objects
    print("Original JSON:")
    print(json.dumps(original_json, indent=4))
    print("
    Deep Copied JSON:")
    print(json.dumps(deep_copied_json, indent=4))

  • @adityasinghh04
    @adityasinghh04 9 місяців тому

    For Deep Copying
    const myFruits = JSON.parse(JSON.stringify(fruits))
    const user2 = JSON.parse(JSON.stringify(user1))
    Episode 23 completed bhaiya ji. Good night. Kal milte hain bhaiya. ❤

    • @procodrr
      @procodrr  9 місяців тому

      Good night ❤️

  • @ytshortssk2477
    @ytshortssk2477 Рік тому +16

    agar pahle pata chalta apke channel ka to mere 70000 bach jate

    • @procodrr
      @procodrr  Рік тому +17

      Koi baat nahi bro, jyada tension mat lo. Tum bas achhe se padhai karo job lagegi to sab waapas aa jayega.
      Keep Learning and Sharing 😊

    • @_sarthakmisal
      @_sarthakmisal 11 місяців тому +4

      Sach me 70k waste kare tune JS pe😂

    • @OMKUMAR-sc4qv
      @OMKUMAR-sc4qv 3 місяці тому +1

      Joot mat bol bro Tera sakal sai lagta hai ki tum 1 poor admi hai admi hai 😂😂😂

  • @sunilvishwakarma5687
    @sunilvishwakarma5687 8 місяців тому

    JSON.parse(JSON.stringify(nestedobj));

  • @pawantiwari8570
    @pawantiwari8570 7 місяців тому

    I found this code on mdn

  • @aadilyt1573
    @aadilyt1573 7 місяців тому

    😍❤

  • @AmanGupta-w6g
    @AmanGupta-w6g Місяць тому

    const obj1 = {
    firstName: 'Chaman',
    lastName: 'Chutiya',
    pata: {
    city: 'Bangalore',
    country: 'India',
    pinCode: 121005,
    },
    }
    // deep copy
    const obj2 = JSON.parse(JSON.stringify(obj1))
    this is deep copy synatx

  • @talib7508
    @talib7508 2 роки тому +3

    Json.stringify karke
    But when it comes to functions inside json.stringify fails there
    Simple solution use lodash

    • @procodrr
      @procodrr  2 роки тому +1

      Yes, correct 👍

    • @amanyadav7526
      @amanyadav7526 2 роки тому

      Lodash ka use kar sakte hai ( Functions bhi kaam kartein hain uske sath )

  • @Itsasifvlog01
    @Itsasifvlog01 14 днів тому

    ..........

  • @user-un3lj7iu7v
    @user-un3lj7iu7v 8 місяців тому

    Pehle khud cheezko ko study kro aur logo ko tum toh khrab kr doge bhai deep copy kaha btaya don't see this video guys it's not correct

    • @Vikas-sc4jd
      @Vikas-sc4jd 8 місяців тому +2

      bhai kitni spoon fedding chaiye apko?

    • @user-un3lj7iu7v
      @user-un3lj7iu7v 8 місяців тому

      @@Vikas-sc4jd tumhe need hai

    • @trainerdevesh
      @trainerdevesh 5 місяців тому

      Bhai sir ek well experience developer Bangalore me job krte hai hai aur har developer kabhe n kabhe kuch chize bhul jaata he hai @@user-un3lj7iu7v

  • @vamsikrishnasayarwar1792
    @vamsikrishnasayarwar1792 6 місяців тому

    Deep copy can be achieved by using JSON.stingify and JSON.parse
    const user1={firstName:'Anurag',lastName:'Singh',pata:{city:'Delhi',pincode:'998988'},subject:['Physics','CS','Math']}
    const user2=JSON.parse(JSON.stringify(user1))//Creates Deep Copy

  • @shubhamstutorialspoint5908
    @shubhamstutorialspoint5908 8 місяців тому

    const names = {
    firstName: "alka",
    lastName: "Sharma",
    pata: {
    firstLine: "jssgh",
    secondLine: "shsh",
    pincode: 978766,
    nearBuy: { naerone: "hdfhh", near2: "dbbfh" },
    },
    subject: ["chem", "CS", "Math"],
    };
    // Shallow COPY (SPREAD OPERATOR {...})
    // const names2 = { ...names };
    // DEEP COPY (JSON METHOD)
    const names2 = JSON.parse(JSON.stringify(names));
    names2.lastName = "verma";
    names2.pata.pincode = 12345;
    names2.subject.push("Bio");
    names2.pata.nearBuy.near2 = "qwerty";
    console.log(names2);
    console.log(names);

  • @prohulkgaming8734
    @prohulkgaming8734 5 місяців тому

    const user1 = {
    firstname : 'Hukma',
    lastname : 'Choudhary',
    pata : {
    city : "Jaipur",
    pincode : 302012
    },
    subjects : ['maths','chemistry','physics','js', 'cs']
    }
    // const user2 = {...user1} //Shallow Copy
    // Deep copy
    const user2 = JSON.parse(JSON.stringify(user1));

    • @mitamaji7706
      @mitamaji7706 3 місяці тому

      Sir @procodrr,
      What about this?
      const user2 = structuredClone(user1)
      // Deep copy

  • @satish_kumar_pandit_7371
    @satish_kumar_pandit_7371 5 місяців тому

    const employee = {
    eid: "E102",
    ename: "Jack",
    eaddress: "New York",
    salary: 50000
    }
    console.log("=========Deep Copy========");
    const newEmployee = JSON.parse(JSON.stringify(employee));
    console.log("Employee=> ", employee);
    console.log("New Employee=> ", newEmployee);

  • @arzoo3094
    @arzoo3094 2 місяці тому

    DeepCopy
    Const obj1 = {
    fName: 'Arzoo',
    lName:'Duddy',
    moreInfo:{
    City: 'Gurgaon',
    Pincode: 123456,
    },
    Const newObj = JSON.parse(JSON.stringify(ojb1)) 50:05