admin管理员组

文章数量:1335138

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

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

Share Improve this question asked Jun 19, 2013 at 18:24 BartFurglarBartFurglar 31 gold badge1 silver badge2 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 3

If what you are asking is how you iterate over the contents of an array, you can do so in plain javascript like this:

var arr = [1,2,3];

for (var i = 0; i < arr.length; i++) {
    // arr[i] is each item of the array
    console.log(arr[i]);
}

Just because something is of type Object does not necessarily mean that it's an array. It could also just be a plain object with various properties on it. If you look at the info argument in either the debugger or with console.log(info), you should be able to see what it is.

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;
}

本文标签: How to return all objects in javascript arrayStack Overflow