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

164
Views
¿Por qué un valor en una matriz solo está indefinido cuando lo configuro en una función?

Tengo una matriz que consta de objetos, cada uno de los cuales contiene

 let videos = [ { link: 'https://www.youtube.com/watch?v=umW2AwxZGV0', title: 'title', thumbnail: "thumbnail" }, { link: 'https://www.youtube.com/watch?v=CTxISFb84IU', title: 'title', thumbnail: "thumbnail" }, { link: 'https://www.youtube.com/watch?v=Wn_Kb3MR_cU', title: 'title', thumbnail: "thumbnail" }, { link: 'https://www.youtube.com/watch?v=lWAOefb5jCU', title: 'title', thumbnail: "thumbnail" }, { link: 'https://www.youtube.com/watch?v=qj9KR7KMKFs', title: 'title', thumbnail: "thumbnail" } ];

Además, tengo una función que devuelve la ID de video de un enlace de youtube.

 function YouTubeGetID(url) { url = url.split(/(vi\/|v=|\/v\/|youtu\.be\/|\/embed{\/)/); let videoID = url[2] !== undefined ? url[2].split(/[^0-9a-z_\-]/i)[0] : url[0]; return videoID; }

Usando un paquete npm, recupero el título (el código está abajo).

 for (let i = 0; i < videos.length; i++) { let videoId = YouTubeGetID(videos[i].link); getYoutubeTitle(videoId, ytApiKey, function (err, title) { if (err) { throw err; } videos[i].title = title; }) videos[i].thumbnail = `http://img.youtube.com/vi/${videoId}/default.jpg` }

Con este bucle for, obtengo el enlace de mi matriz, obtengo la identificación y busco el título. Si coloco el title console.log( console.log() dentro getYoutubeTitle() obtengo el título correcto del video. Pero si quiero configurar videos[i].title = title no se arroja ningún error. Pero si registro la matriz de videos, el título no cambia (también conocido como el título no está definido).

¿Alguien me puede ayudar?

about 4 years ago · Santiago Trujillo
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!