JavaScript object data and Arrays
<p>I have a JavaScript object as follows.</p>

<pre><code>var sampleData = {
    "studentsList": {
        "Student1": {
            "marks": "123",
            "grade": "B"
        },
        "Student2": {
            "marks": "144",
            "grade": "A"
        }
    }
};​
</code></pre>

<p>Now the user enters the name of a student, say <code>Student1</code> and I need to get the details of that object. </p>

<p><strong>I have two questions.</strong></p>

<p><strong>[1]</strong> How do I get the details of the entered student using JavaScript? </p>

<p>When I use <code>sampleData.studendsList.valueOf("Student1")</code> returns me the complete object. I just need the details of "Student1".</p>

<p><strong>[2]</strong> Is this the correct way to do it? Or we should create an array of Students and that contains an property called "name" with value say <code>Student1</code> ? If I go with this approach then I need to iterate through the entire array list to get the details of a student. </p>

<p>Which appraoch is better?</p>
