TIL20 - JS - Array

Peter D Lee·2020년 8월 30일
0

JavaScript

목록 보기
9/19

1. Array

In JavaScript, an 'array' is a list data type indicated by [], with array 'elements' inside separated by ,

> ex)

let array1 = ['element1', 'element2', 'element3'];

2. Array Index

individual elements of an array can be access or replaced by referencing the index of the array

The index number starts with 0 - the first element of an array has the index number of 0, the second element 1, the third element 2, and so on

> ex)

let arrayPractice = ['el1', 'el2', 'el3', 'el4'];
let firstEl = arrayPractice[0];
let secondEl = arrayPractice[1];
console.log(firstEl); // Prints: el1
console.log(secondEl); // Prints: el2

> ex2)

// same arrayPractice from above
arrayPractice[0] = 'element1'
console.log(arrayPractice);
//Prints: ['element1', 'el2', 'el3', 'el4']

3. Array Methods

0개의 댓글