Coming soon - Get a detailed view of why an account is flagged as spam!
view details

This post has been de-listed

It is no longer included in search results and normal feeds (front page, hot posts, subreddit posts, etc). It remains visible only via the author's post history.

1
Grabbing certain things from Array of Objects
Post Body

Like my previous post said, I'm still very new to JS. I'm currently looking at a practice problem where I'm given an array of objects labeled as classroom. Within it, there are several key sections and the one I'm currently trying to grab is the "assignments" section.

I started out like this

let assignmentsGrab = classroom.assignments
console.log(assignmentsGrab)

This ends up working and shows me all of the assignment entries. Now I'm having trouble accessing a specific one based on its ID and grabbing its name and point value. This is the code itself I'm trying to access. For example, if I want to grab the name and points of id:103, how would I go about it. I'm assuming I'm going to need a for loop but I'm not sure how the syntax of it would go for this.

assignments: [
    {
      id: 101,
      name: "Intro",
      pointsPossible: 5,
    },
    {
      id: 102,
      name: "Lesson 1",
      pointsPossible: 10,
    },
    {
      id: 103,
      name: "Lesson 2",
      pointsPossible: 10,
    },
    {
      id: 104,
      name: "Final",
      pointsPossible: 30,
    }
  ]

^These are all inside the classroom object and assignments is the next level down.

Author
Account Strength
100%
Account Age
5 years
Verified Email
Yes
Verified Flair
No
Total Karma
9,114
Link Karma
553
Comment Karma
8,165
Profile updated: 2 days ago
Posts updated: 1 month ago

Subreddit

Post Details

We try to extract some basic information from the post title. This is not always successful or accurate, please use your best judgement and compare these values to the post title and body for confirmation.
Posted
3 years ago