Search code examples
javascriptarraysflashflowplayercaption

How to return all objects in javascript array


I have a variable that is created by Flowplayer and available via javascript. If I write the variable to the page directly it just returns 'object Object' so I am assuming this is an array. If I don't know the names of any of the objects inside the array, how can I parse out the data inside?

I know I am missing something really fundamental here, but I don't think I have ever had to get data from an array not knowing what it contains.

Notes:

  • What I am trying to do is get the onCuePoint caption data embedded into an RTMP video stream
  • .valueOf() returns the same thing
  • Here is the code I am using that returns 'object Object':

streamCallbacks: ['onFI'],
clip:

{
    live:true,          
    provider: 'rtmp',
    autoPlay: true,
    url:'test1',
    onFI:function(clip, info)
    {
        document.getElementById("onFI").innerHTML += "Data: " + info;
    }
}

Thank you


Solution

  • You need to iterate through your array and get the results one by one, replace your onFI function with this :

    onFI:function(clip, info)
    {
        var data = "";
    
        // For each value in the array
        for (var i = 0; i < info.length; i++) 
        {
             // Add it to the data string (each record will be separated by a space)
             data += info[i] + ' ';
        }
    
        document.getElementById("onFI").innerHTML += "Data: " + data;
    }