I didn't know that the function won't get copied using stringify. Thanks for pointing that out and here is the solution to the homework problem let person = { firstName: "Harshit", lastName: "Badolla", fullName(){ return `${this.firstName} is ${this.lastName}`; } }; let keys = Object.keys(person); function deepCopy(arr) { const newObj = {} for(let i = 0; i
We can improve the solution by passing an object as an argument and moving the keys variable inside the function deepcopy...this way it will become more like the lodash method which you used in the video. Let me know what you think? Also lodash method will check for all corner cases but the function which i wrote can also be used.
let person = { firstName: "Harshit", lastName: "Badolla", fullName(){ return `${this.firstName} is ${this.lastName}`; } }; function deepCopy(obj) { let keys = Object.keys(person); const newObj = {} for(let i = 0; i
@@Harshitbadolla this is still the shallow copy not deep copy.. Try with below obj let person = { firstName: "Harshit", lastName: "Badolla", address: { location: 'Pune', hometown: 'Mumbai' }, fullName(){ return `${this.firstName} is ${this.lastName}`; } }; If we change address.location for one object it gets changed for another object too. @sofia Can you suggest how we can make it deepcopy (and make it work for nested objs too)? [I am also trying, will post here if I find soln]
@@namratagiri4240 const deepCopyFunction = (inObject) => { let outObject, value, key if (typeof inObject !== "object" || inObject === null) { return inObject // Return the value if inObject is not an object } // Create an array or object to hold the values outObject = Array.isArray(inObject) ? [] : {} for (key in inObject) { value = inObject[key] // Recursively (deep) copy for nested objects, including arrays outObject[key] = deepCopyFunction(value) } return outObject }; I got the above solution from here - javascript.plainenglish.io/how-to-deep-copy-objects-and-arrays-in-javascript-7c911359b089 Thanks for pointing out...I got to learn something new. Also it is always best to use a library to deep copy like lodash as there will be lot of corner cases which needs to be taken care of. All the best 👍
Mam , I have started learning JavaScript, CSS and HTML from 2 months...from online resources... Please tell me when can I get a job as frontend developer
Honestly there is no certain answer to this.. It completely depends on your grasping power... But i am sure that if you keep learning and practicing you will get a job soon... All the best.. 👍
You need to have lodash added to your project... Clonedeep is a method of lodash... www.google.com/amp/s/www.geeksforgeeks.org/lodash-_-clonedeep-method/amp/
Nice explanation now I am clearing my all doubts.
Taught us in a very nice manner and not consumed lot of time.........
ZABARDAST ... CONTINUE RAKHIEN APNAY LECTURES ...
love your work you just make it very simple and clear that too with giving each and every exact tiny detail ,may godbless you❤️
Thanks a lot 🙏
Good one... Appreciate the explanation.. I'm ready to face this question now😎
Good to know that 🙂
You are a great teacher. I have started to see you js playlist. it is very good.
Thanks 🙏 react tutorials are also coming soon if you are interested
beauty with knowledge killer combo thanks a lot
Thank you very much😄
I didn't know that the function won't get copied using stringify. Thanks for pointing that out and here is the solution to the homework problem
let person = {
firstName: "Harshit",
lastName: "Badolla",
fullName(){
return `${this.firstName} is ${this.lastName}`;
}
};
let keys = Object.keys(person);
function deepCopy(arr) {
const newObj = {}
for(let i = 0; i
Superb yr...keep going... 👍
We can improve the solution by passing an object as an argument and moving the keys variable inside the function deepcopy...this way it will become more like the lodash method which you used in the video. Let me know what you think? Also lodash method will check for all corner cases but the function which i wrote can also be used.
let person = {
firstName: "Harshit",
lastName: "Badolla",
fullName(){
return `${this.firstName} is ${this.lastName}`;
}
};
function deepCopy(obj) {
let keys = Object.keys(person);
const newObj = {}
for(let i = 0; i
@@Harshitbadolla this is still the shallow copy not deep copy..
Try with below obj
let person = {
firstName: "Harshit",
lastName: "Badolla",
address: {
location: 'Pune',
hometown: 'Mumbai'
},
fullName(){
return `${this.firstName} is ${this.lastName}`;
}
};
If we change address.location for one object it gets changed for another object too.
@sofia Can you suggest how we can make it deepcopy (and make it work for nested objs too)?
[I am also trying, will post here if I find soln]
@@namratagiri4240
const deepCopyFunction = (inObject) => {
let outObject, value, key
if (typeof inObject !== "object" || inObject === null) {
return inObject // Return the value if inObject is not an object
}
// Create an array or object to hold the values
outObject = Array.isArray(inObject) ? [] : {}
for (key in inObject) {
value = inObject[key]
// Recursively (deep) copy for nested objects, including arrays
outObject[key] = deepCopyFunction(value)
}
return outObject
};
I got the above solution from here -
javascript.plainenglish.io/how-to-deep-copy-objects-and-arrays-in-javascript-7c911359b089
Thanks for pointing out...I got to learn something new.
Also it is always best to use a library to deep copy like lodash as there will be lot of corner cases which needs to be taken care of. All the best 👍
simply excellent....
Good one, I would like to see concept of functional programming in js like HOC with prons and cons and closures with prons and cons.
Coming up with closures soon...
great information for new man job interview
Thanks..
so knowledgeable
hi...
very informative .
Thanks 🙏
Wonderfully explained. 👍
Thanks buddy... 🙃
Well Explained...
Mam ap esse hi videos laya kijiye so that we can crack the interview
Sure... Working on more... 😊
Knowledgeable Content👍
Awesome explanation 🙂.
Nice 👌
Thanks a lot
Thanks alot 👍
Hi mam,
I am giving the interview in front end how can I practice tricky js question.
I think you need to know js in depth, then you will be able to solve them all
Mam , I have started learning JavaScript, CSS and HTML from 2 months...from online resources... Please tell me when can I get a job as frontend developer
Honestly there is no certain answer to this.. It completely depends on your grasping power... But i am sure that if you keep learning and practicing you will get a job soon... All the best.. 👍
@@SofiaGoyal thanks mam..could u guide me for getting a starting job as Front end developer.. what should i do more to get job ASAP..
mam clone deep nahi mill raha extention me.
You need to have lodash added to your project... Clonedeep is a method of lodash...
www.google.com/amp/s/www.geeksforgeeks.org/lodash-_-clonedeep-method/amp/
Mam mera error a raha Uncaught TypeError: JSON.stringfy is not a function
stringify ki spelling yaha galat hai to program m bh hogi
Mam Event loop Javascript ka video bna do kafi puchte hai interview mai pr actual mai niii pta
Sure... Will Come with that soon...
please pick all the topics to js ...
mam object.seeze and object.freez par video banaea.
Sure.. Will try
@@SofiaGoyal mam sorry it is Object.freeze vs Object.seal ess par videos banaea.
Ye concept koye java mai bhi bta do:(
Thanks a lot