Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

259
Visualizações
How would I go about retrieving the `release_date`

How would I go about retrieving the release_date and then removing everything from that except the year, in the example it would be 2022

There is MULTIPLE results that would need this so... im clueless on how to approach this.

Code:

const endpoint = `https://api.themoviedb.org/3/movie/popular?api_key=${apikey}&language=en-US&page=1`;

const fetchMovies = (endpoint) => {
  fetch(endpoint)
    .then((result) => result.json())
    .then((result) => {
      console.log([...result.results]);
    });
};

fetchMovies(endpoint);

Example of output:

[
  {
    adult: false,
    backdrop_path: '/8pgKccb5PfE1kWB9qqiXJem83VC.jpg',
    genre_ids: [ 28, 53 ],
    id: 522016,
    original_language: 'en',
    original_title: 'The 355',
    overview: 'A group of top female agents from American, British, Chinese, Columbian and German  government agencies are drawn together to try and stop an organization from acquiring a deadly weapon to send the world into chaos.',
    popularity: 1276.737,
    poster_path: '/uQt2dJFMnJmAp9zLAWNfGilK0BW.jpg',
    release_date: '2022-01-05',
    title: 'The 355',
    video: false,
    vote_average: 6.1,
    vote_count: 261
  }
]
about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0


const endpoint = `https://api.themoviedb.org/3/movie/popular?api_key=${apikey}&language=en-US&page=1`;

const fetchMovies = (endpoint) => {
  fetch(endpoint)
    .then((result) => result.json())
    .then((result) => {
      const res = result.results.map((movie) => {
        const releaseYear = movie.release_date.split("-")[0];
        return { ...movie, release_date: releaseYear }
      });
      console.log(res);
    });
};

fetchMovies(endpoint);

Notice that, I am using map to get the same number of results back while modifying the release_date. We can split the date string by "-" and get the first index to retrieve only year part.

about 4 years ago · Juan Pablo Isaza Relatório

0

Use getFullYear(). If output = result.results then try this:

// output = result.results;
output = [
  {
    adult: false,
    backdrop_path: '/8pgKccb5PfE1kWB9qqiXJem83VC.jpg',
    genre_ids: [ 28, 53 ],
    id: 522016,
    original_language: 'en',
    original_title: 'The 355',
    overview: 'A group of top female agents from American, British, Chinese, Columbian and German  government agencies are drawn together to try and stop an organization from acquiring a deadly weapon to send the world into chaos.',
    popularity: 1276.737,
    poster_path: '/uQt2dJFMnJmAp9zLAWNfGilK0BW.jpg',
    release_date: '2022-01-05',
    title: 'The 355',
    video: false,
    vote_average: 6.1,
    vote_count: 261
  }
]

const res = output.map((movie) => {
    movie.release_date = new Date(movie.release_date).getFullYear();
    return movie;
});
console.log(res);

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda