I have an array formed by a series of objs, I would like to make sure to assign an object to a variable.
If the object doesn't exist I would like to assign {} (empty obj).
Can you give me some advice?
let a = [
{
username: 'james.bond',
name: 'James Bond',
email: '[email protected]',
},
{
username: 'sherlock.holmes',
name: 'Sherlock Holmes',
email: '[email protected]',
},
{
name: 'Shinichi Kudo',
email: '[email protected]',
badgeText: '21',
badgeColor: '#fff',
badgeBackground: '#25dbd2',
joined: 'Joined at Jun 31, 2021',
circle: ['transparent', 'transparent'],
},
{
name: 'Arthur Conan Doyle',
email: '[email protected]',
circle: ['transparent', 'transparent'],
},
];
const [b = {}, c = [] ] = a;
console.log(b, c);//b=a[0], c=[a[1],a[2],a[3]]