I hope so anyway
As part of my Knowledge is Power series, I aim to post once a week about something I've learned. This week one of the things I've learned about is Arrays.
The push() method simply adds an element to the end of the array and increases its length. It's not limited to one element, you can add more than one simply by adding a comma and another element.
The pop() method does the opposite of what push() does at the end of the array, it simply 'pops' what's at the end and removes it (only one element at a time).
The unshift() method adds an element to the beginning of the array and increases its length. It's not limited to one element, you can add more than one simply by adding a comma and another element.
The shift() method 'shifts' an element (at a time) from the beginning of the array and removes it.
Things are getting interesting, the map() method creates a new array with the results of calling a function.
Check this; the function runs on every element within the array.
The some() method tests whether at least one of the elements in the array passes the test within the called function.
The every() method tests if all the elements in the array pass the test within the function - it returns a Boolean value.
In the below example, you can see it returns false but do you know which number is causing it to return false?
You don't need to find which number is causing it to return false, just use the .find() method! The find() method returns the value of the first element in the provided array that satisfies the provided testing function. If no value satisfies the testing function, it will return
These are just some of the array methods out there but these are just the ones that I've been exposed to over the last few days.
Because you got down this far, enjoy this visualisation of some array methods that I put together, it made me chuckle.
If you're still reading, thank you so much, I hope to use this blog to post and share useful information I gain! I would love to connect with other developers to see what they're learning and learn from them - please connect with me on the following: