Its best to work in chrome. Open a new tab (about:blank) and right click and choose inspect then click on console.
var todos = ['item 1', 'item 2', 'item 3']
- todos is the name of my variable.
- The items are in an array. Which is like a list of items.
console.log('My to do list:', todos)
- Console.log() prints whatever is in the brackets.
- You can join items between the brackets.
- If you put quotation marks it prints whatever is inside them.
- As todos isn't in quotation marks it prints out the contents of the variable.
- You can add items to the array by calling the variable and 'pushing' another item to the end of the array.
- When you press enter, the console returns the number of items in the array.
todos = 'item 1 updated'
- To edit the array item you call the variable and in square brackets put the item number you want.
- Computers start counting at zero so item number one is item 0.
- Then you just put what you want the new value to be after an equals sign in quotation marks.
- Call the array and then use splice
- To use this you need brackets.
- The first number is the position at which you start deleting, the second number is how many items you delete.
- In this example, you just delete the first item in the array.