Async wait Promise

<!DOCTYPE html>
<html lang="en">
<body>
    <script>
        function sleep(ms) {
            return new Promise(resolve => setTimeout(resolve, ms));
        }
        const annoncement = async () => {
            document.body.insertAdjacentHTML("afterBegin"
, `<h1 id="info">date: ${new Date().toLocaleDateString()}</h1>`);
            await sleep(3000)
            document.querySelector("#info").remove();
        }
        annoncement();
    </script>
</body>

</html> 

delete

     const titi = "TITI";

    const body = {"toto":"TOTO",titi,"_id":"23"}
    delete body._id;
    const thing = {...body};
   
    console.log(thing)

PS C:\Users\denis.dupont\OneDrive - Universite Evry Val d'Essonne\Bureau\testgenerateur> node .\test.js { toto: 'TOTO', titi: 'TITI' }

lodash

 https://lodash.com/docs/4.17.15#pullAllBy

Object.fromEntries

Exemples

const cours = { html: 12, css: 2, JS: 30 };

Object.entries(cours)

> Array [Array ["html", 12], Array ["css", 2], Array ["JS", 30]]

Object.fromEntries(Object.entries(cours))

> Object { html: 12, css: 2, JS: 30 }


En action

const cours = { html: 12, css: 2, JS: 30 };
const  choix = Object.fromEntries(
  Object.entries(cours)
  .filter(([ _, val ]) => val>10 )
);
console.log(choix); // > Object { html: 12, JS: 30 }

En action

const words = ["Beau", "cool", "Ange", "Ananas", "ballon"]; const alpha = words.reduce((a, x) => { const l = x[0].toUpperCase() if(!a[l]) a[l] = []; a[l].push(x); return a; }, {}); const glosaire = Object.fromEntries( Object.entries(alpha) .sort(([a] , [b]) => a<b?-1:1)); console.log(glosaire); //
  • [object Object] {
      A
    : ["Ange", "Ananas"],
      B
    : ["Beau", "ballon"],
      C
    : ["cool"]
    }

regexp

 function normalizeDataKey(key) {

    return key.replace(/[A-Z]/g, chr => `-${chr.toLowerCase()}`);
  }

  console.log(normalizeDataKey("denisDupont")) // denis-dupont

destructuration, map

const arr = [{

    id: 1,
    name: 'bill'
  }, {
    id: 2,
    name: 'ted'
  }]
  
const result = arr.map( ({id:value,name:text}) => ({ value, text }));
  console.log(result)

` `

 function test(lit,...sub){

    console.log(lit);
    console.log(sub);

}
const nom = "dupont"
const adj = "cool"

test `denis ${nom} est ${adj}`;