Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width">
  <title>JS Bin</title>
</head>
<body>
</body>
</html>
 
// declare an empty array
const names = []
// print the (currently empty) array to the console 
console.log(names)
// Add a value to an array using .push() method
names.push("Nemo")
// print the names array after adding a value to it
console.log(names)
// Add another name to the names array
names.push("Dory")
// print updated array to the console
console.log(names)
names.push("Bubbles")
names.push("Mr. Ray")
console.log(names);
// reference an element in the array by passing the index of the array
// and placing it in a square brackets next to the array holding those items
const character = names[2]
// print out character name to the console
console.log(character + " is a character from Finding Nemo")
// print out the number of characters currently stored in the array
console.log(names.length)
// Swap "Mr. Ray" with "Crush"
names[3] = "Crush"
console.log(names)
Output

You can jump to the latest bin by adding /latest to your URL

Dismiss x