Object.values/Object.entries

Object.values is the opposite of Object.keys, gets the values. Object.entries returns an array with arrays of key-value pairs

const obj = {
    name: 'Shane',
    age: 23,
    sex: 'male'
}

// ['Shane', 23, 'male']
Object.values(obj);

//[['name', 'shane'],['age', 23],['sex', 'male']]
Object.entries(obj);

String Padding

The padStart() method pads the current string with another string until the resulting string reaches the given length. The padding is applied from the start of the current string. padEnd() does the opposite.

// aaaaashane
'shane'.padStart(10, 'a');

// shaneaaaaa
'shane'.padEnd(10, 'a');

Trailing Commas in Functions

There are two benefits:

  • You don’t have to add and remove commas if the last item changes its position.
  • It helps version control systems with tracking what actually changed.
function test(
  a,
  b,
) {
  return {a,b};
}