I have an object which has several values I want to extract and place into another object with different keys for those values. Right now I'm using deconstruction to extract the values, then defining an object literal with those extracted values and their new keys.
Here is my function:
getProductReviewData() {
const {
averageRateDisplay,
rawAverageRate,
displayReviewCount,
productReviewIds,
productReviews
} = this.productReviewsStore.getAll(); // this is deconstruction of an object
return {
ratingDisplay: averageRateDisplay,
rating: rawAverageRate,
ratingCount: displayReviewCount,
reviewIds: productReviewIds,
reviewMap: productReviews
};
}
However, I was wondering if is a shorthand way to do this, so use one line for both the deconstruction and the declaration. Does anyone know if this is possible?
See Question&Answers more detail:os