How to alias a JavaScript destructor variable

Starting in ES6, you can deconstruct an object. What this means is that you can set a variable to just one key from an object. Deconstructing is useful when you only need specific keys from an object. Below is an example JSON response.

{
"status": 200,
"code": "success",
"message": "The post was saved successfully"
}

You can destruct the response to only get the status and message. Let's say that we are making a call with JS promises to create a new blog post.

const data = {
title: 'This is a test',
body: 'Here is the body of my new blog post!'
}

fetch('https://example.com/post', {
method: 'POST'
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(data),
}).then(({data: post}) => {
console.log(post);
});

If you look at the .then() part of the Ajax call, you will see ({data: post}) this is the part aliasing the variable from the response. JSON fetched from the server has the data variable, but in our JS, we will be using the post variable instead. So to obtain the title, we would use post.title, which would give us "This is a test."