0 added
0 removed
Original
2026-01-01
Modified
2026-03-09
1
<p>We will continue refactoring a bit later. And now we will learn how to work with arrays.</p>
1
<p>We will continue refactoring a bit later. And now we will learn how to work with arrays.</p>
2
<p>An array is a one-piece list, and therefore it can be written into one variable and this variable can be transferred to some command, for example, to muffin.plot(). Isn’t it much more convenient than transferring a bunch of individual variables to a command?</p>
2
<p>An array is a one-piece list, and therefore it can be written into one variable and this variable can be transferred to some command, for example, to muffin.plot(). Isn’t it much more convenient than transferring a bunch of individual variables to a command?</p>
3
<p>When processing arrays, you almost always need to get its individual values. To get an array element, you need to specify the ordinal number or the<em>index</em>of this element in the already familiar to us square brackets.</p>
3
<p>When processing arrays, you almost always need to get its individual values. To get an array element, you need to specify the ordinal number or the<em>index</em>of this element in the already familiar to us square brackets.</p>
4
var numbers = [1, 2, 3, 4, 5]; // Logs 2 in the console console.log(numbers[1]);<p>But why was the two logged, and not the one? The numbering of elements in the array starts with a zero: the first element of the array goes under number zero, the second under number one, the third under number two and so on.</p>
4
var numbers = [1, 2, 3, 4, 5]; // Logs 2 in the console console.log(numbers[1]);<p>But why was the two logged, and not the one? The numbering of elements in the array starts with a zero: the first element of the array goes under number zero, the second under number one, the third under number two and so on.</p>
5
<p>By the way, if you find it difficult to remember such an unusual way of numbering, you can use the year analogy: chronology and age counting also start from zero. If a person is 25 years old, it means that they are on 26th year of life. From 2000 to 2004, Michael Schumacher won five championship titles in a row.</p>
5
<p>By the way, if you find it difficult to remember such an unusual way of numbering, you can use the year analogy: chronology and age counting also start from zero. If a person is 25 years old, it means that they are on 26th year of life. From 2000 to 2004, Michael Schumacher won five championship titles in a row.</p>
6
<p>Let’s sum it all up. To get the first element of the array, for example, usersByDay, you need to write usersByDay[0]. The variable name indicates that we are accessing an array. The square brackets indicate that we do not need the entire array, but only one of its elements. We mark the number of the element we need using the square brackets.</p>
6
<p>Let’s sum it all up. To get the first element of the array, for example, usersByDay, you need to write usersByDay[0]. The variable name indicates that we are accessing an array. The square brackets indicate that we do not need the entire array, but only one of its elements. We mark the number of the element we need using the square brackets.</p>
7
<p>Let’s try reading a few more entries from the array usersByDay.</p>
7
<p>Let’s try reading a few more entries from the array usersByDay.</p>