29 lines
656 B
Markdown
29 lines
656 B
Markdown
|
# .cadoles-slide-title[Tableaux (1/2)]
|
||
|
|
||
|
**Différentes notations**
|
||
|
```js
|
||
|
var arr = [1, 2, 3]; // A préférer
|
||
|
arr = new Array(1, 2, 3);
|
||
|
|
||
|
// Attention !
|
||
|
arr = new Array(3); // -> [undefined, undefined, undefined]
|
||
|
```
|
||
|
**Manipulation d'un tableau**
|
||
|
```js
|
||
|
var arr = [1, 2, 3];
|
||
|
|
||
|
// Propriétés
|
||
|
arr.length // -> 3
|
||
|
arr[0] // -> 1
|
||
|
|
||
|
// Méthodes (liste non exhaustive)
|
||
|
arr.push(4); // -> [1, 2, 3, 4]
|
||
|
arr.pop(); // -> [1, 2, 3]
|
||
|
arr.unshift(0); // -> [0, 1, 2, 3]
|
||
|
arr.shift(); // -> [1, 2, 3]
|
||
|
arr.indexOf(2) // -> 1
|
||
|
arr = [2, 3, 1];
|
||
|
arr.sort(); // -> [1, 2, 3]
|
||
|
arr.join(', '); // -> '1, 2, 3'
|
||
|
```
|