简体   繁体   中英

how to destruc an object which includes a long string with dot as the key

I have an object which includes string with dot "journey.hintText.journeyTags" as the key. (returned by api response i cannot modify). I would like to destruct content object like const {journey.hintText.journeyTags} = content, but it throws error. Please let me know how I can destruct content object, thanks a lot.

const content = {journey.hintText.journeyTags: 'Please select a tag'}

You can use computed properties, but you should provide the name like this const { ['journey.hintText.journeyTags']: journeyTags } = content

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM