The second day of array stuff is here! Wes started out with Array.prototype.some and Array.prototype.every which are functions I’m familiar with, and he also introduces the trick of console logging variables when surrounding them with curly brackets. I think this is an ES6 thing, and I didn’t learn it from this course, but I have been showing it to a lot of people over the past few years, so it’s definitely worth sharing.

let foo = "bar";
console.log({foo});

Normally you’d probably just console.log foo which would result in “bar” being printed in the console, but adding the curly brackets makes it into an object and there’s a shortcut in ES6 that puts the key of the variable name and the value of the variable value if you just drop a variable into an object. This is not just for console.log, it works everywhere.

The other array stuff this lesson touches on are find which takes a function and returns the first thing that the function returns true for, and findIndex which returns the array index of the first thing that the function returned true for.

The final part is to find a particular comment in an array of comment objects and remove it. As with the other Array Cardio exercise, I did this one and then watched the video. I used delete to remove the comment from the array. In the video he talks about using either splice to modify the array in place, or using slice (twice) while spreading (...) the result to create a new array. This is pretty common with React where you want to be sure you’re treating your state as immutable, so every time you want to change a thing that is in state (including useState hooks) you should be creating a new object.

For today’s exercise, I don’t think I’ve personally used find before, but I did see it in a pull request earlier this week so it wasn’t brand brand new. So I will put “find” and splice and slice (also functions I’ve used but always have to look up which does what) in my list of stuff I learned about today.

On to day 8!