is there a syntax with javascript es6 or es-next to achieve the following behavior
let t = {
text: 'hello world',
[shouldShow ? ...{'show' : 'test text'} : ''],
test: 21
}
I want that if shouldShow is true the object t should be
{
text: 'hello world',
show: 'test text',
test: 21
}
and if shouldShow is false the object t will be
{
text: 'hello world',
test: 21
}
I know, I can do that with if/else but I'm asking if there is a syntax that I can use for just one line of code