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"]
    }