Coding diary day 5: Arrays var fruits = [β€˜πŸ‰β€™, β€˜πŸ“β€™, β€˜πŸβ€™, β€˜πŸŽβ€™]

Array Object

  • The Array object is used to store ordered list of multiple values in a single variable such as the above (see screenshot) fruits variable
  • Array indexes, just like strings, are zero-based: the first element is positioned at index 0, the second at index 1 and so on. E.g., πŸ‰ in the above fruits variable is positioned at index 0
  • Arrays are considered objects in JavaScript but more on that later

Empty Arrays

  • Guess what, an array does not need to have anything in it to be still considered an array

New Functions I learned today

Use variables as an argument

  • Declare a function that takes an array parameter and returns it

A function that takes in an Array + Index

  • Now, declare a function that takes in an array AND an index, and returns the element located at the inputted index

Create a variable inside of a Function

  • Declare a function that takes no parameters, creates an array, and returns the newly created array

Next lesson, Objects, so stay tuned

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store