Merge pull request #244 from usernamehw/patch-2

Update article.md
This commit is contained in:
Ilya Kantor 2017-10-15 18:02:37 +03:00 committed by GitHub
commit 24411a8de8

View file

@ -297,7 +297,7 @@ But for arrays there is another form of loop, `for..of`:
let fruits = ["Apple", "Orange", "Plum"];
// iterates over array elements
for(let fruit of fruits) {
for (let fruit of fruits) {
alert( fruit );
}
```
@ -356,7 +356,7 @@ arr.length = 5; // return length back
alert( arr[3] ); // undefined: the values do not return
```
So, the simplest way to clear the array is: `arr.length=0`.
So, the simplest way to clear the array is: `arr.length = 0;`.
## new Array() [#new-array]
@ -385,9 +385,9 @@ In the code above, `new Array(number)` has all elements `undefined`.
To evade such surprises, we usually use square brackets, unless we really know what we're doing.
## Multidimentional arrays
## Multidimensional arrays
Arrays can have items that are also arrays. We can use it for multidimentional arrays, to store matrices:
Arrays can have items that are also arrays. We can use it for multidimensional arrays, to store matrices:
```js run
let matrix = [
@ -458,9 +458,9 @@ We can use an array as a deque with the following operations:
- `unshift(...items)` adds items to the beginning.
To loop over the elements of the array:
- `for(let i=0; i<arr.length; i++)` -- works fastest, old-browser-compatible.
- `for(let item of arr)` -- the modern syntax for items only,
- `for(let i in arr)` -- never use.
- `for (let i=0; i<arr.length; i++)` -- works fastest, old-browser-compatible.
- `for (let item of arr)` -- the modern syntax for items only,
- `for (let i in arr)` -- never use.
We will return to arrays and study more methods to add, remove, extract elements and sort arrays in the chapter <info:array-methods>.