Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8215887
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T11:56:14+00:00 2026-06-07T11:56:14+00:00

I have a JavaScript object as follows. var sampleData = { studentsList: { Student1:

  • 0

I have a JavaScript object as follows.

var sampleData = {
    "studentsList": {
        "Student1": {
            "marks": "123",
            "grade": "B"
        },
        "Student2": {
            "marks": "144",
            "grade": "A"
        }
    }
};​

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

I have two questions.

[1] How do I get the details of the entered student using JavaScript?

When I use sampleData.studendsList.valueOf("Student1") returns me the complete object. I just need the details of “Student1”.

[2] 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 Student1 ? If I go with this approach then I need to iterate through the entire array list to get the details of a student.

Which appraoch is better?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T11:56:16+00:00Added an answer on June 7, 2026 at 11:56 am

    An array is usually the more natural way to store a list of items (like students). But there are tradeoffs. As structured (using objects), you can access any student by name in constant time:

    sampleData.studentsList.Student1
    

    Structuring with an array looks like this:

    var sampleData = {
        "studentsList": [
            {
                "marks": "123",
                "grade": "B"
            },
            {
                "marks": "144",
                "grade": "A"
            }
        ]
    };​
    

    Access the nth student like this:

    sampleData.studentsList[n]
    

    If the index of the desired student is not known, then accessing a particular student (based on its details) is O(n) (because you’d need to iterate the entire array to find the correct item in the worst case).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Javascript object created as follows: var ccStatTracker = (function (){ ccmap:{
I have a JavaScript object as follows: var a = { Prop1: 'test', Prop2:
I have a javascript object like so: var object = [{ id: 1, title:xyz
Lets say I have a Javascript object: var myObj = { property1 : 20,
I have a JSON object as follows: var jsonObject = {regex:<span class=\Value\>\\$(.+?)<\\/span>}; My target
I have created a JavaScript extension for an array object as follows: Array.prototype.where =
In javascript I have an array as follows: var foo = [2, 2, 4,
Just wonder. I have extended javascript Array object using its prototype as follows: <html>
Often during writing JavaScript, we have to write configuration object. For example Ext.define('User', {
Lets say I have created an object and its properties in JavaScript as follows-

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.