Lab 27 Reflection

     Lab 27 was mainly about using JS references to refer to an array. This lab was completely done in the console like Labs 18 and 22. I started off by creating a new array of player names and logged this in the console. I wanted to add a player to the array but I didn't want to change the current array, so I created a new empty array and used .concat(array) to merge the old and new array. This didn't change or get rid of the old array, rather, it copied all the items in the old array into the new array. From there, I could just use .push() to add a new player.
     These skills are useful when coding to preserve certain arrays the way they are. If a website has a list of items the user could add or subtract from and these items are stored in an array, making a copy and manipulating a copy of the original array instead of the original itself allows you to implement a feature that reverts the list to default, if there was a default selection of items. Since the original array is unchanged, all you would have to do for this is take the current values and replace them with the original. Such preservation keeps data that could be useful later on from changing.

Comments

Popular Posts