Update article.md
This commit is contained in:
parent
b4ee23ce2c
commit
089af82ee2
1 changed files with 7 additions and 7 deletions
|
@ -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>.
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue