<link href="https://fonts.googleapis.com/css?family=Poppins:600" rel="stylesheet">

<main class="container">
  <h1>
    JavaScript Array `at()`
  </h1>
</main>
* {
  box-sizing: border-box;
  font-family: inherit;
  font-size: inherit;
  font-style: inherit;
}

body {
  background: #1D1F21;
  font-family: Inter, sans-serif; 
  font-size: 16px;
  font-style: normal;
  font-size: 1.75em;
  color: #ede7f6;
}

.container {
  height: 100vh;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  text-align: center;
}

h1 {
  font-size: 5rem;
  background: linear-gradient(to right, #ef5350, #f48fb1, #7e57c2, #2196f3, #26c6da, #43a047, #eeff41, #f9a825, #ff5722);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}
// The at() method takes an integer value and returns the item at that index. The value can be either a positive or negative integer. Negative integers count back from the last item in the array.


// Test out at() by passing in different values. 
// Open the CodePen console below to see the results. 

const colors = ['red', 'orange', 'yellow', 'green', 'blue', 'purple'];

console.log(colors.at(0)); // red

console.log(colors.at(-1)); //purple

console.log(colors.at(3)) // green

Run Pen

External CSS

This Pen doesn't use any external CSS resources.

External JavaScript

This Pen doesn't use any external JavaScript resources.