Not much to talk about this week. Still same old luck on the job hunting front, I followed up on a job someone personally connected me to, but it looks like they didnt respond because they are looking for programmers who know Python and Django, which we did not cover at FlatIron. I have my check in with my career coach today so hopefully I can get some good advice.
For the technical portion of the blog, lets talk about JavaScript(JS) arrays and review the cool tools JS offers us to manipulate them. An array in JS is an ordered list of values, the values can be strings, numbers, booleans, and even objects! Array values are indexed from the first one being index 0, and so on. To declare an array in JS, you can type the following:
const array = ["Mike", 35, true];
Arrays, are always wrapped in square brackets ([]), and each element is separated by a comma. In this array, the “Mike” sits at index 0, the 35 is 1 and true is 2.
JS has many tools to allow you to manipulate arrays, lets check out a few of them. To declare a new variable from just one specific element in an array, you can do the following:
let name - array[0];
Now, the variable ‘name’ will equal ‘Mike.’ This method lets you access elements in your array by simply using the index number.
If you decided you’re not done with your array and want to add another element to it, you can use the push method like so:
array.push("Blog");
Now, the array would be:
const array = ["Mike", 35, true, "Blog"];
With whatever you pushed added to the end of the array.
If you want the element to go to the start of the array (element index 0) you can do the same thing, but in place of ‘push,’ use unshift:
array.unshift("Blog");
If you want to remove an element from the array, you can use the pop method to remove the last element, or the shift method to remove the first:
const array = ["Mike", 35, true, "Blog"];array.pop();console.log(array);
>> array = ["Mike", 35, true];array.shift();console.log(array);
>> array = [35, true];
These are ‘destructive’ methods that will change the original array. If you want to keep that array and create a copy of it to manipulate, you can use the slice method:
const array = ["Mike", 35, true, "Blog"];const arrayCopy = array.slice()
There are many more array operators and ways to manipulate that you can learn, hopefully this was a good intro to all the cool things you can do with arrays in JS!