But you would see that, if we try to actually do that with an array, we would have a problem because although we can't redefine this variable or this constant, like this, with myArray equals five, because we're changing the value of this array, this would throw an error. We can actually change the values of these elements using this notation. So this would work just fine, and you could change the value of the first element to anything you want here. Now, that works because arrays are assigned not by their values, or not to values, but they're assigned by reference.
So let's take a look at an example of how that works. Here's a way of creating an array that becomes mutable, because of the way that we've designed it. So we've got this array right here, and we want to increment it. And we can, if we want to, go ahead and use the forEach method. And the forEach method is going to take each of the items and add one to them. Now, the problem with this is that we're actually modifying each of the elements in the array.
And that could be fine, but it could present problems. Because in a complicated program, it's better if we create a function that's not actually modifying the originals, but is always working in a copy. When you're programming things that could change at some point while they're executing, creating mutable arrays is a little bit dangerous. So we usually want to write this in a different way, and the forEach method is probably not the best method to use here. Now, we've seen before that we can use something called a map, which is specifically designed to work with this sort of pattern, where we want to change a series of elements.
Skill Level Intermediate
Q: Why can't I earn a Certificate of Completion for this course?
A: We publish a new tutorial or tutorials for this course on a regular basis. We are unable to offer a Certificate of Completion because it is an ever-evolving course that is not designed to be completed. Check back often for new movies.