After receiving movie data from an api, I am currently manually creating a new object with a subset of properties and modified values. Is there a more efficient way to achieve this using javascript/typescript object destructuring syntax?
I specifically want to use some existing properties like title
and overview
, but need to change the value of poster_path
property. Can this be done in a concise manner?
movieCollection.results.forEach(
(movie: {
poster_path: string,
backdrop_path: string,
title: string,
overview: string,
release_date: string,
vote_average: number,
vote_count: number,
genre_ids: number[],
}) => {
if (movie.backdrop_path) {
//create paths for pictures
let poster_path = this.secureBaseURL + this.posterSizes[4] + movie.poster_path;
let backdrop_path = this.secureBaseURL + this.posterSizes[5] + movie.backdrop_path;
//create array object
movieArray.push({
poster_path: poster_path,
backdrop_path: backdrop_path,
title: movie.title,
overview: movie.overview,
release_date: movie.release_date,
vote_average: movie.vote_average,
vote_count: movie.vote_count,
genre_ids: movie.genre_ids,
styles: {},
});
}
});