aderaaij
11/12/2017 - 9:36 PM

ES6 String improvements

Examples of the .startsWith(), .endsWith(), .includes() and .repeat() es6 javascript methods.

const course = 'RFB2';
const flightNumber = '20-AC2018-jz';
const accountNumber = '825242631RT0001';

const make = 'BMW';
const model = 'x5';
const colour = 'Royal Blue';

// .startsWith(searchString [, position])
// https://developer.mozilla.org/nl/docs/Web/JavaScript/Reference/Global_Objects/String/startsWith
console.log(flightNumber.startsWith('AC', 3))
// .endsWith()

// .includes()

// .repeat()

function leftPad(str, length = 20) {
  return `→ ${' '.repeat(length - str.length)}${str}`;
}

console.log(leftPad(make));
console.log(leftPad(model));
console.log(leftPad(colour));