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

205
Views
How to extract an Array from API response

Hello I am using https://www.npmjs.com/package/ytfps package to get the URLs and titles from youtube playlists. The format given as response to ytfps(url).then(playlist =>{console.log(util.inspect(playlist))} is the following:

{
   title: 'Music Playlist',
   url: 'https://www.youtube.com/playlist?list=PLoXvI0xCls_7WZpfvrqwBNqlnZTMylyTvdo6',
   id: '7WZpfvrqwBNqlnZTMylyTvdo6',
   video_count: 16,
   view_count: 16,
   description: '',
   isUnlisted: false,
   thumbnail_url: 'https://i.ytimg.com/vi/jBmkNzfqFZUSW4/hqdefault.jpg',
   author: {
     name: 'Default',
     url: 'https://www.youtube.com/user/gadfgagaq',
     avatar_url: 'https://yt3.ggpht.com/ytc/AKedOLQoEJLXJMV2t3MRgadfqNuhWk46GwnYr7r1DAgnGbsQ=s176-c-k-c0x00ffffff-no-rj'
   },
   videos: [
     {
       title: 'Barei - Say Yay! (Eurovision 2016 Spain)',
       url: 'https://www.youtube.com/watch?v=jBmkNzFZUW4',
       id: 'jBmkNzFZUW4',
       length: '3:07',
       milis_length: 187000,
       thumbnail_url: 'https://i.ytimg.com/vi/jBmkNzFZUW4/hqdefault.jpg',
       author: [Object]
     },
     {
       title: 'Sound of Silence',
       url: 'https://www.youtube.com/watch?v=4S6sT_2gM2o',
       id: '4S6sT_2gM2o',
       length: '3:16',
       milis_length: 196000,
       thumbnail_url: 'https://i.ytimg.com/vi/4S6sT_2gM2o/hqdefault.jpg',
       author: [Object]
     },

   ]
}

What I want is to get 2 arrays one of URLs and the other one of titles, like this:

url= [https://www.youtube.com/watch?v=jBmkNzFZUW4', 'https://www.youtube.com/watch?v=4S6sT_2gM2o', and so on... ]
titles =['Barei - Say Yay! (Eurovision 2016 Spain)', 'Sound of Silence', and so on ]

So what is the best way to extract those 2 arrays?

about 4 years ago · Juan Pablo Isaza
3 answers
Answer question

0

You can declare two separate arrays, map the videos array on your object and push to those arrays accordingly,

Like:


const videoTitle = [];

const videoUrl = [];

playlist.videos.map(v => {
  
    videoTitle.push(v.title)
    videoUrl.push(v.url);
});
  
about 4 years ago · Juan Pablo Isaza Report

0

You need just to iterate videos. Then, for each video, you extract the url and put the result in an urls array. The same for the title, you extract the title and put the result in an titles array.

Something like :

const urls = [];
const titles = [];

playlist.videos.forEach(video => {
    urls.push(video.url);
    titles.push(video.title);
});

console.log(urls);
console.log(titles);
about 4 years ago · Juan Pablo Isaza Report

0

try This :

let urls = [];
let titles = [];
playlist.videos.forEach(element => {
    urls.push(element.url);
    titles.push(element.title);
 });

 console.log("urls",urls);
 console.log("titles",titles);
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!