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

151
Views
Make the code take one number at a time and embed in it

I'm trying to use an API in my code that downloads media from Instagram posts.

The response passed by the API is as follows:

{
    post1: {
        url: 'download url',
        type: 'media type' 
    },
    post2: {
        url: 'download url',
        type: 'media type' 
    }
}

post1, post2, and so on depending on the number of posts on that link (up to 10 posts).

i would like it to query and get the url of each of them.

var resultsMedia = await apis.insta_post(link)

I tried

resultsMedia.post[i].url

(i refers to a for function I tried, for var i = 1; ...) and I was not successful.

I would like to know how I could make the resultsMidia.post take one number at a time example: resultsMedia.post1.url, resultsMedia.post2.url, resultsMedia.post3.url, and so on.

(resultsMedia refers to the API call, post refers to the api response, and url is a parameter also present in the API response)

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

0

You can try this:

 const postCount=Object.keys(resultsMedia).length; for (let i = 1;i<=postCount;i++){ console.log(resultsMedia[`post${i}`]) }
about 4 years ago · Juan Pablo Isaza Report

0

You can iterate using Object.entries() :

 const response = { post1: { url: 'download url 1', type: 'media type' }, post2: { url: 'download url 2', type: 'media type' } } Object.entries(response).forEach(([post, data]) => { console.log('---------------') console.log('Post:', post) console.log('Post number:', +post.replace('post', '')) console.log('Data:', data) console.log('Data url:', data.url) console.log('---------------') })

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!