November 2016
Intermediate to advanced
480 pages
14h 42m
English
You have been doing a lot of tinkering with your bucket list array. But you can also create an array that cannot be changed, called an immutable array. Here is how.
Let’s say you are making an application that allows users to keep track of the lunches they eat each week. Among other things, users will log what they ate and generate reports at a later time. You decide to put these meals in an immutable array to generate the reports. After all, it does not make sense to change last week’s lunches after they have been eaten.
Create an immutable array and initialize it with a week’s worth of lunches.
Listing 9.17 An immutable array
...
let lunches = [
"Cheeseburger",
"Veggie Pizza",
"Chicken Caesar Salad",
"Black ...Read now
Unlock full access