The Fibonacci Sequence is the series of numbers:
0, 1, 1, 2, 3, 5, 8, 13, 21, 34, . . .
There are 3 ways of creating arrays.
1. Create an array object
2. Create an Array object by instantiating the Array object.
3. Create an Array object by inserting collection data
After creating an Array object, we can insert data. Use
 with index if you want to assign the value.
push method adds an element to the array and returns the arrayâ€™s length.
In the example below we use the
push() function to insert data.
In the example below we'll use the
push method to add an element to an array and then log the count of elements in the array to the console.
To access array data, you can use
 with data index parameter.
pop method removes the last element in the array and returns that elementâ€™s value.
Arrays have additional built-in variables and functions, which are also known as properties and methods, that provide addtional value when working with arrays in code.
An arrayâ€™s length property provides the number of elements contained within the array.
concat method returns a new array that combines the values of two arrays. Which is useful if you want to join two arrays to each other.
reverse method returns a copy of the array in opposite order.
splice() method adds/removes items to/from an array, and returns the removed item(s).
I'll create a simple node.js application which will illustrate how to make use of arrays.
The code below includes a reference to simple Fibonacci sequence generator class which exposes two methods to generate a Fibonacci sequence, Looping or Recursion, the source code for the class is included in the GitHub Repository.
Our console window should look something similar to the below with all our values contained in the array printed out
To update an item of array data, you can use
 with data index and thus assign a new value.
You can use the
pop() function to remove data from the Array.
pop() method removes the last element from an array and returns that element.
If you want to remove data by specific index then you can use the
Arrays are simply data types that can store more than one variable. Each variable is stored in an array element.
Arrays are usually Zero-bound so the first element in the array is always 0.
As programmer you will be required to develop and implement algorithms for a variety of tasks, As tasks become more complex algorithm development is facilitated by structuring or organizing data in specialized ways.
Arrays are suitable data structures that can be selected for the specific task Some data structures are provided by programming languages others must be derived by the programmer from available data types and structures.
- How to add Fathom Analytics to Nuxt 3 - May 19, 2023
- How to use Azure Blob Storage - May 8, 2023
- How to use Azure Key Vault to manage secrets - April 30, 2023