javascript / beginner
Snippet
Checking Array Length
The length property of an array returns the total number of elements it contains.
snippet.js
1
2
const colors = ['red', 'green', 'blue'];console.log(colors.length);
nodejs
Breakdown
1
const colors = ['red', 'green', 'blue'];
Creates a constant array named colors with three string elements.
2
console.log(colors.length);
Accesses the length property of the array and prints the result (3) to the console.