I have received an object with address details in alphabetical order that I need to extract a specific subset from and display them in a different sequence.
Some keys may have an empty string instead of no data at all.
const address = {
buildingName: '',
company: 'My org',
county: 'My County',
postCode: 'My Postcode',
streetName: 'My street',
townCity: 'My Town'
};
I am aware that I can retrieve all values by using:
Object.keys(address).filter(Boolean).join(', ')
However, I want the information to be displayed in the following order:
company, buildingName, streetName, townCity, county, postCode
.
Is there a way for me to modify my current solution or should I consider a different approach?