Earlier ECMAScript versions were named by numbers, such as ES5 and ES6. Starting in 2016, versions are referred to by the year of release, like ES2016, ES2018, ES2020, and so on.
This chapter covers the new features introduced in ECMAScript 2017:
ES2017 has been fully supported in all modern browsers since September 2017.
ECMAScript 2017 introduced two string methods to JavaScript: padStart() and padEnd(), which allow padding at the beginning and end of a string, respectively.
let text = “5”; text = text.padStart(4,0); |
let text = “5”; text = text.padEnd(4,0); |
JavaScript string padding has been supported in all modern browsers since April 2017.
ECMAScript 2017 introduced the Object.entries() method, which returns an array of key/value pairs from an object.
const person = { firstName : “John”, lastName : “Doe”, age : 50, eyeColor : “blue” }; let text = Object.entries(person); |
The Object.entries() method makes it easy to iterate over objects in loops.
const fruits = {Bananas:300, Oranges:200, Apples:500}; let text = “”; for (let [fruit, value] of Object.entries(fruits)) { text += fruit + “: “ + value + “<br>”; } |
The Object.entries() method also simplifies converting objects into maps.
const fruits = {Bananas:300, Oranges:200, Apples:500}; const myMap = new Map(Object.entries(fruits)); |
The Object.entries() method has been supported in all modern browsers since March 2017.