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 extrac
UPD: Simple is better than complex! I like Bergi's answer =)
Probably you can declare new keys and then change them in iterations ¯_(ツ)_/¯
getProductReviewData() {
//declare new keys
const newKeys = {
averageRateDisplay: "ratingDisplay",
rawAverageRate: "rating",
displayReviewCount: "ratingCount",
productReviewIds: "reviewIds",
productReviews: "reviewMap"
}
const productReviewsStore = this.productReviewsStore.getAll();
//return the object with replaced keys
return Object.assign({},
...Object.keys(productReviewsStore)
.filter(key => newKeys[key])
.map(key => ({[newKeys[key]]: productReviewsStore[key]}))
)
}