Handle Large JSON Response
NodeJS
Medium
4 views
Problem Description
Fetch JSON (mocked) and safely handle missing fields.
Output Format
Print one line.
Constraints
Mock fetch returns nested object.
Official Solution
async function getData() {
return { user: { name: 'meetcode' } };
}
(async () => {
const data = await getData();
const name = data && data.user && data.user.name ? data.user.name : 'meetcode';
console.log('Hello ' + name);
})();
Solutions (0)
No solutions submitted yet. Be the first!
No comments yet. Start the discussion!