Some advanced tips for ES6

aifou
4 min readApr 15, 2024
Some advanced tips for ES6

ES6 (ECMAScript 2015) introduced many new features and syntax, some of which may be relatively obscure, but very practical. This article will introduce some of these advanced tips, including

  • Object.entries()
  • Object.fromEntries()
  • Symbol type and Symbol properties
  • WeakMap and WeakSet
  • Promise.allSettled()
  • BigInt
  • Array.of
  • Array.from
  • .at和flat

1.Object.entries() and Object.fromEntries()

  • Object.entries() method returns an array of key-value pairs of a given object’s own enumerable properties.
  • Object.fromEntries() method converts a list of key-value pairs into an object.

When using Object.entries(), you can pass in an object as a parameter. This object can be any object that has enumerable properties. For example:

const obj = { a: 1, b: 2, c: 3 };

const entries = Object.entries(obj);
console.log(entries); // [["a", 1], ["b", 2], ["c", 3]]

In this example, we pass an object that contains three properties to the Object.entries() method and store the returned result in the entries variable. The entries variable is now an…

--

--