map

const liste = [
{age:10,arg:2,exp:2},
{age:1,arg:1},
{age:100,arg:3},
];

function AgeArg({arg,age}){
  return age*arg;
}

let T = liste.map(AgeArg);

console.log(T);

reduce : destructuring

const liste = [
{age:10,arg:2,exp:2},
{age:1,arg:1},
{age:100,arg:3},
];

function AgeArg(acc,{arg,age}){
  return acc+ age*arg;
}

let T = liste.reduce(AgeArg,0);

console.log(T); //321

for_of

const liste = [
{age:10,arg:2,exp:2},
{age:1,arg:1},
{age:100,arg:3},
];

for_of

classique

for (l of liste){
console.log(l.age)
}

destructuring

for ({arg,age} of liste){
console.log(arg*age)
}


foreach array of objet

const liste = [
{age:10,arg:2,exp:2},
{age:1,arg:1},
{age:100,arg:3},
];

forEach

classique

liste.forEach(function(v,i){
console.log(v.arg)
})

arrow

liste.forEach((v,i)=>{
console.log(v.arg)
})

destructuring

liste.forEach(({age,arg},i)=>{
console.log(arg*age)
})




array Random

Array.from({length: Math.random()*9}, (v, k) => k);

Ne pas utiliser V = value qui n'est pas définie

String literal

let t = ["abcdefghi"];

let MyA = t[0].split("");


let v = MyA.reduce((p,n,i) => (i%3===0) ? (`
${p}

${n}`) : `${p} ${n}`);

JS Bin on jsbin.com

Map en action

const allowedKeys = new Map([
        [37, 'left'],
        [38, 'up'],
        [39, 'right'],
        [40, 'down']
]);
document.addEventListener('keydown', function(e) {
 let arrow = allowedKeys.get(e.keyCode);
    if (arrow) document.querySelector("#Key").innerHTML +=`<br/>${arrow}`;
    e.preventDefault();
    return false;
});


JS Bin on jsbin.com