Are multi-dimentional arrays also mutable

I learned that one level arrays(one-dimentional) can be modified, so can multi-dimentional arrays(nested) be modified since they are accessible using square brackets’s indexes?
Thank you

Of course. An array inside an array is still just an array. A good way to learn about these things is to test them for yourself. I’m sure you can come up with a simple example for testing.

I’m also assuming you are referring to the situation when you declare an array using const? If you are talking about something else please let us know.

I didn’t study the const yet im still at the push and pop functions level of the course, the question i asked just came to my mind and i thought they may not cover that possibility here at freecodecamp so.
Or the const is key in this?

No, when declaring variables, the const keyword does not make the array itself immutable. By default you can always modify an array (add items, remove items, change the value of items). Now, you can Object.freeze an array to make it immutable (and you need to do this recursively if the array has other objects/arrays in it that you also want to be immutable). But by default, arrays are always mutable.

1 Like

So by recursively you mean i should use the object.freeze on the arrays that are inside too?

Yes, if you truly want to make the entire thing immutable then you not only need to freeze the primary array but also any arrays that are elements of the primary array, and so on…

1 Like

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.