In this Basic Data Structures posts, you'll learn more about the differences between arrays and objects, and which to use in different situations. You'll also learn how to use helpful JS methods like
Object.keys()to access and manipulate data.
Here is an example of the simplest implementation of an array data structure. This is known as a one-dimensional array, meaning it only has one level, or that it does not have any other arrays nested within it.
let array = ['one', 2, 'three', true, false, undefined, null]; console.log(simpleArray.length);
The `console.log` call displays `7`.
- All arrays have a length property, which as shown above, can be very easily accessed with the syntax Array.length.
- We have the ability to not only store data, but to be able to retrieve that data on command. So, now that we've learned how to create an array, let's begin to think about how we can access that array's information.
- When we define a simple array as seen below:
let myArray = ["a", "b", "c"];
let ourVariable = myArray;
ourVariablehas the value of
In addition to accessing the value associated with an index, you can also set an index to a value using the same notation:
myArray = "e";
- Using bracket notation, we have now reset the item at index 1 from the string
b, to 'e
is["a", "e", "c"]`.