0

When i do console.log(data) on a particular script that i'm using, i get the following

[Object {
    name = "videobody", value = "asdasd"
},
Object {
    name = "IMUFiles[]", value = "selected_arrow1327549445.png"
},
Object {
    name = "filename", value = "testing"
},
Object {
    name = "allow_comments", value = "y"
}]

How can i access selected_arrow1327549445.png from data

5
  • Are you looking for more than data[1].value? Commented Jan 26, 2012 at 3:59
  • 2
    kinda sad when an answer isn't long enough to pass validation... Commented Jan 26, 2012 at 3:59
  • Accessing it directly would be data[1].value or are you wanting to dynamically find it based on something else? Commented Jan 26, 2012 at 4:00
  • order of the objects can change. I'm just looking to grab the filename which in this example is located in the second object Commented Jan 26, 2012 at 4:00
  • How does this structure get assigned to variable. It's invalid Js according to JsLint. Doesn't run : jsfiddle.net/kFQE6 Commented Jan 26, 2012 at 4:03

1 Answer 1

3

It's an array of Objects each with a name and value property, so:

data [1].value

EDIT: Well, since you said the order can change, maybe just loop through:

for (var i = 0; i < data.length; ++ i)
{
    if (data [i].name === "IMUFiles[]")
    {
        alert (data [i].value); 
        break;
    }
}
Sign up to request clarification or add additional context in comments.

6 Comments

it's not necessarily in this particular order. Order of the objects can change.
@Pinkie Do you mean you want to search that value?
So you want to traverse or search the structure?
Yes, that's just the way it's logged to the console.
@gideon yes you're right, it's doesn't validate. This is how i got it from console. I too wonder what is wrong with the code and how to make it work in jsfiddle
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.