ES6

Computed Property trong ES6

const computedPropertyName = ‘five’;
const number = { 
    one: ‘1’
    two: ‘2’,
    [computedPropertyName]: ‘5’ //expression
}
console.log(number);
const number1 = {
    three: ‘3’,
    four: ‘4’,
    [computedPropertyName + ‘ is’]: ‘5’
}
console.log(number1);
const number2 = {
    …number1,
    [computedPropertyName + ‘ is’]: ‘5’
}
console.log(number2);

Leave a Comment