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

91
Views
For each object Javascript

hope all is fine for you I'm a beginner in javascript and i'm trying to integrate a video customer review API on my website. The integration is working on all my pages but on one product page i'd like to init the sdk for each videos id returned by the object to display all the video reviews of this product.

The sdk returned an object as below : enter image description here

And i have to display the sdk like that :

 SDK.init(
            {
                type: "player",
                args: {
                    key: playerKey,
                    id: videoId, // Id returned by the object on the screenshot
                    width: '100%',
                    height: "inherit",
                },
            },
            videoPlayer //=> my div element 
        )

i tried the for each method, objects as below but nothing work for me, each time only 1 player is displaying.

 Object.keys(videos).forEach(id => {
        console.log(videos); 
        SDK.init(
            {
                type: "player",
                args: {
                    key: playerKey,
                    id: videoId,
                    width: '100%',
                    height: "inherit",
                },
            },
            videoPlayer
        )
      });

I have no archive what i tried before this but i'm a little bit lost

Have a nice day and thank you

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

0

The documentation indicates that one HTML element should be dedicated to one player. So you cannot put several players in one element.

You could create child elements inside your container element.

Assuming that videos is an array, like depicted in the screenshot:

videos = [
    { id: '....' },
    { id: '....' }
]

then do this:

for (let {id} of videos) {
    console.log("video ID", id);
    const wrapper = document.createElement("div");
    videoPlayer.appendChild(wrapper);
    SDK.init(
        {
            type: "player",
            args: {
                key: playerKey,
                id,
                /* any other properties you want to add here */
            },
        },
        wrapper
    );
}
about 4 years ago · Juan Pablo Isaza Report

0

I didn't try the SDK, but as @T.J. Crowder mentioned in the comment you probably need to create new <div> for every init call, something like this:

 Object.keys(videos).forEach(id => {
        console.log(videos); 
        const node = document.createElement("div");
        node.style.width = '500px';
        node.style.height = '500px';
    
        videoPlayer.appendChild(node)

        SDK.init({
            type: "player",
            args: {
                key: playerKey,
                id: videoId,
                width: '100%',
                height: "inherit",
            },
        }, node)
      });
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!