Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript JavaScript Objects Loop Through Objects Useful JavaScript Object Methods

karan Badhwar
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
karan Badhwar
Web Development Techdegree Graduate 18,135 Points

... spread operator

As in the ...spread operator example if we do any changes to the Array, that will effect the original value as well right? as it does shallow copy so the inner direct child will be okay, but children of direct children's will be effected. Am i right?

2 Answers

Steven Parker
Steven Parker
229,732 Points

Any nested arrays or objects are just references to the originals. Remember we already talked about this in the question you asked about MDN example two days ago.

In my answer to that other question, I also showed you how to make a "clone" (or "deep copy") if you want all the nested elements also copied so the originals are protected from changes made in the copy.

karan Badhwar
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
karan Badhwar
Web Development Techdegree Graduate 18,135 Points

Yes I understood that on that day sir, actually I was confirming again , that if we change any thing to the skills Key's value which is an array.

In the (Person) Object in which we used ..spread operator so if I modify the (skills) key's value using in the (Person) Object it will have the effect on the (role) Object's skills keys array from which we copied

Steven Parker
Steven Parker
229,732 Points

You might want to experiment with this in the workspace. Seeing it in action for yourself might make it more clear than any explanation.