Академический Документы
Профессиональный Документы
Культура Документы
Po u r D é b u t a n t e n
J AVA S C R I P T (Programmation Internet) V O L . V
Syntaxes :
r = Array.of(10);
console.log(typeof r);
r[2]=29;
console.log(r);
// => [10]
J.D.B. DIASOLUKA Nz. Luyalu JavaScript Tome-V
r = Array.of(78, 90, 25, 33, 56, 36, 39, 96, 93, 35);
console.log(typeof r);
r[11]=30;
console.log(r);
// => (10) [78, 90, 25, 33, 56, 36, 39, 96, 93, 35]
console.log(a1==a1); // true
// La même référence (adresse-mémoire)
console.log(a1===a1); // true
// La même référence (adresse-mémoire)
console.log(a1==a2); // false
// Références (adresses-mémoire) différentes.
console.log(a1===a2); // false
// Références (adresses-mémoire) différentes.
</script>
<script type="text/javascript">
let ar = [34, 20, 90, 41, 74];
ARRAYS en JavaScript 4 / 83 dimanche, 24. mars 2019
J.D.B. DIASOLUKA Nz. Luyalu JavaScript Tome-V
console.log(ar[0], ar[3], ar[5]);
</script>
<script type="text/javascript">
let ar = [34, 20, 90, 41, 74];
console.log(ar[0], ar[3], ar[5]);
// 34 41 undefined
console.log(ar.length); // 5
ar[10] = "Disu";
console.log(ar.length); // 11
var array2 =
["etuci", "alamuki", "daba", "lola", "mbote"]
t="";
for(let i of array2)
t+= array2[self[i]] + "=" + self[i] + " | "
console.log(t)
t="";
for(let i of array2)
t+= ar[self[i]] + "=" + self[i] + " | "
console.log(t)
</script>
<script type="text/javascript">
console.dir(a = new Array(3));
// Tableau à 3 éléments non définis.
console.dir(a[1]); // undefined
console.dir(a = [1,2,3]);
// Tableau à trois éléments : 1, 2 et 3
console.dir(a[1]); // 2
</script>
console.dir(a[1]); // 53
console.dir(a[1]); // 53
console.dir(a[1]); // undefined
console.dir(a[1]); // undefined
console.dir(a[1]); // undefined
// console.dir(a[1][0]);
// TypeError: a[1] is undefined;
// can't access element at index 0
// console.dir(a[1][1]);
// TypeError: a[1] is undefined;
// can't access element at index 1
console.dir(a[1][0]); // abc
console.dir(a[1][1]); // Object { 2: "deux", un: 1 }
console.dir(a[1][2]); // undefined
// console.dir(a[3][0]);
// TypeError: a[3] is undefined;
// can't access element at index 0
console.dir(a[0][0][0]); // 62
console.dir(a[0][0][1]); // 38
console.dir(a[0][1][0]); // 47
console.dir(a[0][1][1]); // chaîne1
console.dir(a[1][0][0]); // abc
console.dir(a[1][0][1]); // undefined
console.dir(a[1][1][0]); // Object { 2: "deux", un: 1 }
console.dir(a[1][1][1]); // 82
console.dir(a[2][1][0][0]); // 83
console.dir(a[2][1][0][1]); // 30
console.dir(a[2][1][1][0]); // 22
console.dir(a[2][1][1][1]); // 62
console.dir(a[2][1][1][2]); // Array(3) [ 44, 28, 99 ]
console.dir(a[2][1][1][2][0]); // 44
console.dir(a[2][1][1][2][1]); // 28
console.dir(a[2][1][1][2][2]); // 99
console.dir(a[3]); // undefined
// console.dir(a[3][0]);
// TypeError: a[3] is undefined;
// can't access element at index 0
console.dir(a = [[10,20,30]]);
// Tableau bidimensionnel
console.dir(a = [...[10,20,30]]);
// Tableau unidimensionnel
// Array(3) [ 10, 20, 30 ]
console.dir(a[0]); // 10
console.dir(a[1]); // 20
console.dir(a[2]); // 30
console.dir(a[0][0]); // undefined
console.dir(a[0]); // 80
console.dir(a[1]); // 92
console.dir(a[2]); // 10
console.dir(a[3]); // 20
console.dir(a[4]); // 30
console.dir(a[0][0]); // undefined
let ar = [10,...[20,30]];
console.dir(a = [80, 92,...ar]);
// Tableau unidimensionnel
// « ar » est la suite d'une array.
// Array(5) [ 80, 92, 10, 20, 30 ]
console.dir(a[0]); // 80
console.dir(a[1]); // 92
console.dir(a[2]); // 10
console.dir(a[3]); // 20
console.dir(a[4]); // 30
console.dir(a[0]); // 80
console.dir(a[1]); // 92
console.dir(a[2]); // Array(3) [ 10, 20, 30 ]
console.dir(a[3]); // undefined
console.dir(a[4]); // undefined
console.dir(a[2][0]); // 10
console.dir(a[2][1]); // 20
console.dir(a[2][2]); // 30
console.dir(a[0]); // 80
console.dir(a[1]); // 92
console.dir(a[2]); // Array [ 10, (2) […] ]
console.dir(a[3]); // undefined
console.dir(a[4]); // undefined
console.dir(a[2][0]); // 10
console.dir(a[2][1]); // Array [ 20, 30 ]
console.dir(a[2][2]); // undefined
<script type="text/javascript">
var [red, green, blue] =
[0xFF0000, 0x00FF00];
console.log([red, green, blue]);
console.dir(Object.entries([red, green, blue]));
console.log("=".repeat(10));
console.log("=".repeat(10));
console.log("=".repeat(10));
console.log("=".repeat(10));
console.log(prémisse);
</script>
<script type="text/javascript">
function* fGenerator() {
let i = 10;
while (true) yield i++;
};
Avec
<script type="text/javascript">
console.log(Array)
</script>
<script type="text/javascript">
console.log ( Array.prototype )
</script>
<script type="text/javascript">
console.log(Object.getOwnPropertyNames(Array))
</script>
<script type="text/javascript">
console.log(Object.getOwnPropertyNames(Array.prototype))
</script>
<script type="text/javascript">
console.log(Object. getOwnPropertyDescriptors(Array))
</script>
Ou pour le prototype :
<script type="text/javascript">
Object. getOwnPropertyDescriptors (Array .prototype)
</script>
<script type="text/javascript">
console.log(Object.getOwnPropertyNames(Array))
</script>
console.log(Object.getOwnPropertyNames(Array.prototype))
console.log(Object. getOwnPropertyDescriptors(Array))
console.log(Object.getOwnPropertyDescriptors (Ar-
ray .prototype))
console.log(Object. getOwnPropertyDescriptors(Array))
{…}
concat: Object { writable: true, enumerable: false, con-
figurable: true, … }
<prototype>: {…}
__defineGetter__: function __defineGetter__()
__defineSetter__: function __defineSetter__()
__lookupGetter__: function __lookupGetter__()
__lookupSetter__: function __lookupSetter__()
ARRAYS en JavaScript 27 / 83 dimanche, 24. mars 2019
J.D.B. DIASOLUKA Nz. Luyalu JavaScript Tome-V
constructor: function Object()
hasOwnProperty: function hasOwnProperty()
isPrototypeOf: function isPrototypeOf()
propertyIsEnumerable: function propertyIsEnumerable()
toLocaleString: function toLocaleString()
toSource: function toSource()
toString: function toString()
valueOf: function valueOf()
console.log(Array)
// function Array()
// Array()
// concat: function concat()
// every: function every()
// filter: function filter()
// forEach: function forEach()
// from: function from()
// indexOf: function indexOf()
// isArray: function isArray()
// join: function join()
// lastIndexOf: function lastIndexOf()
// length: 1
// map: function map()
// name: "Array"
// of: function of()
// pop: function pop()
// prototype: Array []
// push: function push()
// reduce: function reduce()
// reduceRight: function reduceRight()
// reverse: function reverse()
// shift: function shift()
// slice: function slice()
// some: function some()
// sort: function sort()
// splice: function splice()
// unshift: function unshift()
// Symbol(Symbol.species): undefined
console.log(Array.prototype)
console.log(Object. getOwnPropertyDescriptors(Array))
Prototype :
1. prototype:
1. configurable: false
2. enumerable: false
3. value: Array(0)
1. concat: ƒ concat()
2. constructor: ƒ Array()
3. copyWithin: ƒ copyWithin()
4. entries: ƒ entries()
5. every: ƒ every()
6. fill: ƒ fill()
7. filter: ƒ filter()
8. find: ƒ find()
9. findIndex: ƒ findIndex()
10. flat: ƒ flat()
11. flatMap: ƒ flatMap()
12. forEach: ƒ forEach()
13. includes: ƒ includes()
14. indexOf: ƒ indexOf()
15. join: ƒ join()
16. keys: ƒ keys()
17. lastIndexOf: ƒ lastIndexOf()
18. length: 0
19. map: ƒ map()
Prototype du constructeur :
1. __proto__:
1. constructor: ƒ Object()
2. hasOwnProperty: ƒ hasOwnProperty()
3. isPrototypeOf: ƒ isPrototypeOf()
4. propertyIsEnumerable: ƒ propertyIsEnumerable()
5. toLocaleString: ƒ toLocaleString()
6. toString: ƒ toString()
7. valueOf: ƒ valueOf()
8. __defineGetter__: ƒ __defineGetter__()
9. __defineSetter__: ƒ __defineSetter__()
10. __lookupGetter__: ƒ __lookupGetter__()
11. __lookupSetter__: ƒ __lookupSetter__()
12. get __proto__: ƒ __proto__()
13. set __proto__: ƒ __proto__()
Array . fnd ( ) :
console.log(
[30, 52, 47, 16, 30, 50, 39, 26, 79, 49]
.find(isSquare));
console.log{t);
</script>
console.log(
[76, 59, 19, 14, 60, 73, 46, 39, 80, 61]
.find(isSquare));
console.log(t);
</script>
Array . fndIndex ( ) :
const a = [82, 44, 63, NaN, 14, 71, 42, 81, 73, 15];
console.log("a = ",a);
t="";
console.log("a.find(isSquare) = ",a.find(isSquare));
console.log(t);
t="";
console.log("a.findIndex(isSquare) =
",a.findIndex(isSquare));
console.log(t);
t="";
t="";
console.log("a.findIndex(isNaN)) =
",a.findIndex(isNaN));
</script>
a = Array(10) [ 82, 44, 63, NaN, 14, 71, 42, 81, 73, 15 ]
test.html:12:4
82 | test.html:5:8
82 | 44 | test.html:5:8
82 | 44 | 63 | test.html:5:8
82 | 44 | 63 | NaN | test.html:5:8
82 | 44 | 63 | NaN | 14 | test.html:5:8
82 | 44 | 63 | NaN | 14 | 71 | test.html:5:8
82 | 44 | 63 | NaN | 14 | 71 | 42 | test.html:5:8
82 | 44 | 63 | NaN | 14 | 71 | 42 | 81 | test.html:5:8
a.find(isSquare) = 81 test.html:15:4
82 | 44 | 63 | NaN | 14 | 71 | 42 | 81 | test.html:16:4
82 | test.html:5:8
82 | 44 | test.html:5:8
82 | 44 | 63 | test.html:5:8
82 | 44 | 63 | NaN | test.html:5:8
82 | 44 | 63 | NaN | 14 | test.html:5:8
82 | 44 | 63 | NaN | 14 | 71 | test.html:5:8
82 | 44 | 63 | NaN | 14 | 71 | 42 | test.html:5:8
82 | 44 | 63 | NaN | 14 | 71 | 42 | 81 | test.html:5:8
a.findIndex(isSquare) = 7 test.html:19:4
82 | 44 | 63 | NaN | 14 | 71 | 42 | 81 | test.html:20:4
Array . splice ( ) :
Exécution :
Exécution :
Exécution :
2,9,2,3,2,2,7,2,2 vs 2
(1) >==========<
(2) >==========<
INITIAL ARRAY = (9) [2, 9, 2, 3, 2, 2, 7, 2, 2]
SPLICED ARRAY = (8) [2, 9, 2, 3, 2, 2, 7, 2]
DELETED ARRAY = (9) [2, 9, 2, 3, 2, 2, 7, 2, undefined ×
1]
2 a été spliced
===> arrays[7] = undefined après SPLICE() *****
true deleted
===> arrayd[7] = undefined après delete arrayd[7] -----
(3) >==========<
INITIAL ARRAY = (9) [2, 9, 2, 3, 2, 2, 7, 2, 2]
SPLICED ARRAY = (7) [2, 9, 2, 3, 2, 2, 7]
DELETED ARRAY = (9) [2, 9, 2, 3, 2, 2, 7, undefined × 2]
Nothing a été spliced
Nothing deleted
(4) >==========<
INITIAL ARRAY = (9) [2, 9, 2, 3, 2, 2, 7, 2, 2]
SPLICED ARRAY = (7) [2, 9, 2, 3, 2, 2, 7]
DELETED ARRAY = (9) [2, 9, 2, 3, 2, 2, 7, undefined × 2]
2 a été spliced
===> arrays[5] = 7 après SPLICE() *****
true deleted
===> arrayd[5] = undefined après delete arrayd[5] -----
(5) >==========<
INITIAL ARRAY = (9) [2, 9, 2, 3, 2, 2, 7, 2, 2]
SPLICED ARRAY = (6) [2, 9, 2, 3, 2, 7]
DELETED ARRAY = (9) [2, 9, 2, 3, 2, undefined × 1, 7, un-
defined × 2]
2 a été spliced
===> arrays[4] = 7 après SPLICE() *****
true deleted
===> arrayd[4] = undefined après delete arrayd[4] -----
(7) >==========<
INITIAL ARRAY = (9) [2, 9, 2, 3, 2, 2, 7, 2, 2]
SPLICED ARRAY = (5) [2, 9, 2, 3, 7]
DELETED ARRAY = (9) [2, 9, 2, 3, undefined × 2, 7, unde-
fined × 2]
2 a été spliced
===> arrays[2] = 3 après SPLICE() *****
true deleted
===> arrayd[2] = undefined après delete arrayd[2] -----
(8) >==========<
INITIAL ARRAY = (9) [2, 9, 2, 3, 2, 2, 7, 2, 2]
SPLICED ARRAY = (4) [2, 9, 3, 7]
DELETED ARRAY = (9) [2, 9, undefined × 1, 3, undefined ×
2, 7, undefined × 2]
Nothing a été spliced
Nothing deleted
(9) >==========<
INITIAL ARRAY = (9) [2, 9, 2, 3, 2, 2, 7, 2, 2]
SPLICED ARRAY = (4) [2, 9, 3, 7]
DELETED ARRAY = (9) [2, 9, undefined × 1, 3, undefined ×
2, 7, undefined × 2]
2 a été spliced
===> arrays[0] = 9 après SPLICE() *****
true deleted
===> arrayd[0] = undefined après delete arrayd[0] -----
Array . filter ( ) :
Exécution :
(7) [5, 7, 2, 7, 1, 7, 7]
(filter!==7)
(3) [5, 2, 1]
(7) [5, 7, 2, 7, 1, 7, 7]
(filter===7)
(4) [7, 7, 7, 7]
Exécution :
(7) [1, 2, 3, 4, 5, 3, 1]
(3) [2, 3, 5]
ARRAYS en JavaScript 42 / 83 dimanche, 24. mars 2019
J.D.B. DIASOLUKA Nz. Luyalu JavaScript Tome-V
(3) [1, 4, 1]
(4) [2, 3, 5, 3]
Array . map ( ) :
/*
Array [ "770", "047", "909", "240", "005", "574",
"891", "558", "823", "153" ] test.html:8:2
770,047,909,240,005,574,891,558,823,153 test.html:9:2
770,047,909,240,005,574,891,558,823,153 test.html:10:2 */
/*
Array [ "10^^^", "3103^", "5350^", "8623^",
"88^^^" ]
10^^^,3103^,5350^,8623^,88^^^
10^^^,3103^,5350^,8623^,88^^^ */
/*
Array [ "3321^", "7953^", "10^^^", "9682^", "2726^" ]
3321^,7953^,10^^^,9682^,2726^
3321^,7953^,10^^^,9682^,2726^ */
<script>
var srcArray = ["string", 2018, {}];
var destArray = srcArray.map(function(x) {
return typeof x; });
console.log("L'Array de destination = ");
console.log(destArray);
</script>
L'Array de destination =
(3) ["string", "number", "object"]
L'Array de destination =
(3) ["string", "number", "object"]
0:"string"
1:"number"
2:"object"
length:3
__proto__ :Array(0)
L'Array de destination =
Array [ "string", "number", "object" ]
[…]
0: "string"
1: "number"
2: "object"
length: 3
__proto__: Array []
Array . map ( ) :
console.log('=====');
const floor = arr.map(function(el, idx, array) {
res='él['+idx+'] :'+ el+" >= sonFloor ["+
Math.floor(el)+"]";
console.log(res);
// el >= son floor ?
if(el < Math.floor(el)) {
console.log(" ¬")
return false;
}
console.log(" ¥")
return true;
});
Array . forEach ( ) :
La même chose que ci-dessus, mais avec les absolues des opérandes.
console.log('=====');
const floor = arr.forEach(function(el, idx, array) {
res='él['+idx+'] :'+ Math.abs(el)+" >= sonFloor ["+
Math.abs(Math.floor(el))+"]";
console.log(res);
// el >= son floor ?
if(Math.abs(el) < Math.abs(Math.floor(el))) {
console.log(" ¬")
return false;
}
console.log(" ¥")
return true;
});
ARRAYS en JavaScript 48 / 83 dimanche, 24. mars 2019
J.D.B. DIASOLUKA Nz. Luyalu JavaScript Tome-V
console.log('=====');
const ceil = arr.forEach(function(el, idx, array) {
res='él['+idx+'] :'+ Math.abs(el)+" >= sonCeil ["+
Math.abs(Math.ceil(el))+"]";
console.log(res);
// el >= son arrondi ?
if(Math.abs(el) < Math.abs(Math.ceil(el))) {
console.log(" ¬")
return false;
}
console.log(" ¥")
return true;
});
callback
thisArg (Facultatif)
Compute.prototype.ajouter = function(tableau) {
tableau.map(function(el) { // le callback
this.add += el*2; // Somme des doubles.
++this.cptr;
}, this); // this = l'objet Compute.
// ^---- l'argument this ici.
};
// LA MÉTHODE SOME
res = v.some(function(el, idx, array) {
console.log('arr['+idx+']=', el, "< ",
SEUIL_MAX,'? QUITTER ?');
// arr[0]= 5 < 12 ? QUITTER ?
// arr[1]= 2 < 12 ? QUITTER ?
// arr[2]= -16 < 12 ? QUITTER ?
// arr[3]= 14 < 12 ? QUITTER ?
console.log(depart);
// Array(6) [ 0, 1, 2, 3, 9, 10 ]
function retIntB10(el) {
return parseInt(el, 10);
}
console.log(['0', 1.1, '2.2e2', '3e30', '10'].
map(retIntB10)); // Array(5) [0, 1, 2, 3, 10]
function retIntB5(el) {
return parseInt(el, 5);
}
console.log(['0', '60', '2.2e2', '3e30', '10'].
map(retIntB5)); // Array(5) [0, NaN, 2, 3, 10]
</script>
Quand on n’a pas besoin d’une valeur de retour, et que toutes les opéra-
tions doivent se passer et se terminer dans le corps/bloc de la routine,
alors le choix doit être dicté par la rapidité d’exécution.
ARRAYS en JavaScript 54 / 83 dimanche, 24. mars 2019
J.D.B. DIASOLUKA Nz. Luyalu JavaScript Tome-V
let d, b=100000000;
console.log("Array.map");
d=new Date();
for(let k=b;k;k--)arr.map(el => {});
console.log(new Date()-d);
console.log("Array.forEach");
d=new Date();
for(let k=b;k;k--)arr.forEach(el => {});
console.log(new Date()-d);
console.log("Array.every");
d=new Date();
for(let k=b;k;k--)arr.every(el => {});
console.log(new Date()-d);
console.log("Array.some");
d=new Date();
for(let k=b;k;k--)arr.some(el => {});
console.log(new Date()-d);
</script>
Avec
Brave 0.21.18
V8 6.4.388.41
rev 580be78
Muon 4.8.2
OS Release 6.1.7601
Update Channel Release
OS Architecture x64
OS Platform Microsoft Windows
Node.js 7.9.0
Brave Sync v1.4.2
Avec UR
Version 61.1.3163.16 (Build de développement) (BETA)
Avec Sushi
Version du navigateur: 0.21.3
Version chrome : 68.0.3440.84
Version Muon : 8.0.7 :
Une chaîne de caractères est itérable. C’est le seul objet natif ressem-
blant à un tableau, bien que immuables. On peut donc par exemple
soumettre chaque caractère d’une chaîne à la méthode Array.map(),
mais indirectement seulement, via l’appel “ Array.prototype.map.call(),
l’objet itérable à traiter étant le premier argument, et la fonction call-
back le deuxième, le résultat étant naturellement retournée (avec return)
comme array.
console.log(["Un","Deux","Trois"] . join());
// Un,Deux,Trois
console.dir(Object.getOwnPropertyDescriptors(
["Un","Deux","Trois"] . toString()));
console.dir(Object.getOwnPropertyDescriptors(
["Un","Deux","Trois"] . join()));
</script>
if (Array.prototype.every.call(str, estLettre)) {
disp(str);
//La chaîne 'PROGERIA' n'a que des lettres (a - z)
}
if (Array.from(str).map(estLettre)) {
disp(str);
//La chaîne 'PROGERIA' n'a que des lettres (a - z)
function disp(s){
console.log("La chaîne '" + s.toUpperCase() +
"' n'a que des lettres (a - z)");
}
</script>
Une collection aussi étant itérable, peut être soumise à la méthode Ar-
ray . map ( ), indirectement aussi, via l’appel “ Array . prototype .
map . call ( ), l’objet itérable à traiter étant le premier argument, et la
fonction callback le deuxième, le résultat étant aussi retournée (avec
return) comme array.
<select>
<option>Algérie</option>
<option>Lyon</option>
<option>Kinshasa</option>
<option>Petersburg</option>
</select>
<select>
<option>Ford</option>
<option>Opel</option>
<option>Jaguard</option>
</select>
<select>
<option>Terre</option>
<option>Mars</option>
<option>Venus</option>
</select>
array2.push("===== FOREACH");
let rf=array1.forEach(dispEls);
// Ce dispEls = adresse de la fonction callback
// qui elle, porte les arguments.
array2.push("===== MAP");
let rm=array1.map(dispEls);
// dispEls = adresse de la fonction callback.
console.dir("array2=",array2)
// array2= […]
// 0: "===== FOREACH"
// 1: "exp (a[0] = 12) = 162754.79"
// 2: "exp (a[2] = 3) = 20.09"
// 3: "exp (a[4] = 7) = 1096.63"
// 4: "===== MAP"
// 5: "exp (a[0] = 12) = 162754.79"
// 6: "exp (a[2] = 3) = 20.09"
// 7: "exp (a[4] = 7) = 1096.63"
// length: 8
console.log(array1.map(x=>Math.exp(x).toFixed(2)))
// Array [ "162754.79", <1 empty slot>,
// "20.09", <1 empty slot>, "1096.63" ]
// […]
// 0: "162754.79"
// 2: "20.09"
// 4: "1096.63"
// length: 5
console.dir(array1.forEach(x=>Math.exp(x).toFixed(2)))
// undefined
console.log("rm=",rm)
// Array [ 6, <1 empty slot>, 7, <1 empty slot>, 8 ]
// […] , 0: 6 , 2: 7 , 4: 8
// length: 5
</script>
Object.getOwnPropertyNames(Array) :
Object.getOwnPropertyNames(Array.prototype) :
Array . reduce ( ) :
console.log("=".repeat(20));
console.log("=".repeat(20));
console.log("=".repeat(20));
console.log("=".repeat(20));
console.log("=".repeat(20));
console.log("=".repeat(20));
Array . join ( ) :
ARRAYS en JavaScript 69 / 83 dimanche, 24. mars 2019
J.D.B. DIASOLUKA Nz. Luyalu JavaScript Tome-V
console.log ( v );
// Uint8ClampedArray(8)
// [ 86, 8, 255, 14, 125, 149, 255, 66 ]
</script>
Array . split ( ) :
console.log ( v );
// 86 # 8 # 255 # 14 # 125 # 149 # 255 # 66
console.log ( v );
// 86 # 8 # 255 # 14 # 125 # 149 # 255 # 66
</script>
Remarque :
Array . splice ( ) :
console.log ( v );
// Array(8)
// [ "86","8","255","14","125","149","255","66" ]
console.log ( v.splice(3) );
// Array(5) [ "14", "125", "149", "255", "66" ]
console.log ( v );
// Array(3) [ "86", "8", "255" ]
</script>
Syntaxe :
Exemples :
Exécution :
0 test.html:6:3
4 test.html:10:3
4 test.html:14:3
5 test.html:19:3
8 test.html:23:3
undefined test.html:24:3
1 test.html:28:3
Quelletaille test.html:29:3
12 test.html:33:3
undefined test.html:34:3
1 test.html:38:3
1 test.html:42:3
1 test.html:46:3
console.log(arr[0])
console.log(arr[1])
arr[2]
arr[2]()
console.log(arr[2]())
console.log("=====")
for(var i in arr)console.log(i+". "+arr[i])
</script>
Exécution :
rose test.html:9:3
45 test.html:10:3
Hello test.html:6:19
undefined test.html:13:3
===== test.html:14:3
0. rose test.html:15:20
1. 45 test.html:15:20
2. function(){console.log("Hello")} test.html:15:20
console.log(arr[0])
console.log(arr[1])
console.log(arr[2]) // Affiche la fonction
arr[2]() // Exécute la fonction
console.log(arr[2]()) // Ne retourne rien (undefined)
console.log("=====")
for(var i in arr)console.log(i+". "+arr[i])
console.log(Object.entries(arr));
console.log(Object.values(arr));
console.log(">============<");
for(var [cle,val] of Object.entries(arr))
console.log("*"+cle+'^ '+val);
console.log(`=====================================
*** Itération, itérable, itérator ***
=====================================`);
Exécution :
rose test.html:9
45 test.html:10
ƒ (){console.log("Hello")} test.html:11
Hello test.html:6
Hello test.html:6
undefined test.html:13
===== test.html:14
0. rose test.html:15
1. 45 test.html:15
2. function (){console.log("Hello")} test.html:15
(3) [Array(2), Array(2), Array(2)] test.html:16
1 0:(2) ["0", "rose"]
console.log(obj["col"])
// rose
console.log(obj.prix)
// 45
console.log("=====")
console.log(Object.entries(obj));
// Array [ […], […], […] ]
console.log(Object.values(obj));
// Array [ 11(), "rose", 45 ]
console.log(">============<");
console.log(`=====================================
*** Itération, itérable, itérator ***
=====================================`);
console.log(ITERATOR.next())
// Object { value: undefined, done: true }
console.log(ITERATOR.next())
// Object { value: undefined, done: true }
</script>
test.html:8 rose
test.html:11 45
test.html:14 ƒ (){console.log("Hello")}
2test.html:5 Hello
test.html:20 undefined
test.html:23 =====
test.html:25 11. function (){console.log("Hello")}
test.html:25 col. rose
test.html:25 prix. 45
test.html:32 Array(3)
test.html:35 Array(3)
test.html:38 >============<
test.html:41 *11^ function (){console.log("Hello")}
test.html:41 *col^ rose
test.html:41 *prix^ 45
test.html:48 =====================================
*** Itération, itérable, itérator ***
=====================================
test.html:55 Object
test.html:55 Object
test.html:55 Object
test.html:62 Object
test.html:65 Object
Array [] test.html:3:3
### arr.push("1. Pushed") ==> 1 test.html:4:3
Array [ "1. Pushed" ] test.html:5:3
### arr.unshift("2. Unshifted") ==> 2 test.html:6:3
Array [ "2. Unshifted", "1. Pushed" ] test.html:8:3
### arr.push("3. 2nd Push") ==> 3 test.html:9:3
Array [ "2. Unshifted", "1. Pushed", "3. 2nd Push" ] test.html:10:3
### (4. arr[arr.length]="ARR.LENGTH") ==> 4. ARR.LENGTH test.html:11:3
Array [ "2. Unshifted", "1. Pushed", "3. 2nd Push", "4. ARR.LENGTH" ]
test.html:13:3
### 5a. (r=arr.slice(0,2)) ==> 2. Unshifted,1. Pushed test.html:14:3
### 5b. (s=arr.slice(2)) ==> 3. 2nd Push,4. ARR.LENGTH test.html:15:3
Array [ "2. Unshifted", "1. Pushed", "3. 2nd Push", "4. ARR.LENGTH" ]
test.html:16:3
Array [ "2. Unshifted", "1. Pushed" ] test.html:17:3
Array [ "3. 2nd Push", "4. ARR.LENGTH" ] test.html:18:3
### 6. (c1=r.concat(s)) ==> 2. Unshifted,1. Pushed,3. 2nd Push,4. ARR.LENGTH
test.html:19:3
Array [ "2. Unshifted", "1. Pushed", "3. 2nd Push", "4. ARR.LENGTH" ]
test.html:20:3
c1=2. Unshifted,1. Pushed,3. 2nd Push,4. ARR.LENGTH test.html:21:3
### 7. (c2=r+["Add1","Add2"]+s) ==> 2. Unshifted,1. PushedAdd1,Add23. 2nd
Push,4. ARR.LENGTH test.html:22:3
Array [ "2. Unshifted", "1. Pushed", "3. 2nd Push", "4. ARR.LENGTH" ]
test.html:24:3
2. Unshifted,1. PushedAdd1,Add23. 2nd Push,4. ARR.LENGTH test.html:25:3
### 8. (c2=r.concat(["Add1","Add2"]).concat(s)) ==> 2. Unshifted,1.
Pushed,Add1,Add2,3. 2nd Push,4. ARR.LENGTH test.html:26:3
Array [ "2. Unshifted", "1. Pushed", "3. 2nd Push", "4. ARR.LENGTH" ]
test.html:29:3
Array [ "2. Unshifted", "1. Pushed", "Add1", "Add2", "3. 2nd Push", "4.
ARR.LENGTH" ] test.html:30:3
### 9. (arr2=r.join(" <=> ") ==> 2. Unshifted <=> 1. Pushed test.html:31:3
2. Unshifted <=> 1. Pushed test.html:32:3
Array [ "2. Unshifted", "1. Pushed" ] test.html:33:3
Array [ "3. 2nd Push", "4. ARR.LENGTH" ] test.html:34:3
2. Unshifted <=> 1. Pushed test.html:35:3
### 10. (arr2="La bave du crapeau".split(" ") ==> La,bave,du,crapeau
test.html:36:3
Array [ "La", "bave", "du", "crapeau" ] test.html:37:3
### c2.shift("11. Shifted") ==> 2. Unshifted test.html:38:3
Array [ "1. Pushed", "Add1", "Add2", "3. 2nd Push", "4. ARR.LENGTH" ]
ARRAYS en JavaScript 80 / 83 dimanche, 24. mars 2019
J.D.B. DIASOLUKA Nz. Luyalu JavaScript Tome-V
test.html:39:3
### c2.pop("12. Poped") ==> 4. ARR.LENGTH test.html:40:3
Array [ "1. Pushed", "Add1", "Add2", "3. 2nd Push" ] test.html:41:3
### 13. c2.splice(0,1) ==> 1. Pushed test.html:42:3
Array [ "Add1", "Add2", "3. 2nd Push" ] test.html:43:3
Array.forEach :
Exécution :
Mots-clés :
destructuring, destructuration, every, filter, find, fndIn-
dex, forEach, from, indexOf, isArray, join, lastIndexOf,
length, map, splice, includes, push, of, pop, concat, re-
duce, reduceRight, reverse, shift, slice, some, sort, delete,
unshift, Array, objet global, constructeur, tableaux, ob-
jets de haut-niveau, javascript, ecmascript, name, proto-
type
diasfb@mail2world.com