Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

263
Views
¿Cómo haría para recuperar `release_date`?

¿Cómo haría para recuperar la fecha de release_date y luego eliminar todo excepto el año, en el ejemplo sería 2022

Hay MÚLTIPLES resultados que necesitarían esto, así que... no tengo ni idea de cómo abordar esto.

Código:

 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);

Ejemplo de salida:

 [ { 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 answers
Answer question

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);

Tenga en cuenta que estoy usando el map para obtener la misma cantidad de resultados mientras modifico la fecha_de_lanzamiento. Podemos dividir la cadena de fecha por "-" y obtener el primer índice para recuperar solo la parte del año.

about 4 years ago · Juan Pablo Isaza Report

0

Usa getFullYear() . Si salida = resultado.resultados, intente esto:

 // 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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!