How do I properly nest inside an object?

Viewed 28

I'm making a cascading 4 level dropdown. However, how do I nest inside an object? First 3 dropdowns are working perfectly. What I want to accomplish is, when user selects "Links" it will give another option.

var subjectObject = {
  "Front-end": {
    "HTML": ["Links": {"Test": ["test"]}, "Images", "Tables", "Lists"],
    "CSS": ["Borders", "Margins", "Backgrounds", "Float"],
    "JavaScript": ["Variables", "Operators", "Functions", "Conditions"]    
  },
  "Back-end": {
    "PHP": ["Variables", "Strings", "Arrays"],
    "SQL": ["SELECT", "UPDATE", "DELETE"]
  }
}

1 Answers

We can go by the logic of:

  1. If it's nested it's an object.
  2. If not it has array of possible values.

var subjectObject = {
  "Front-end": {
    "HTML": {
      "Links": ["link1", "link2"],
      "Images": null,
      "Tables": null,
      "Lists": null
    },
    "CSS": [
      "Borders",
      "Margins",
      "Backgrounds",
      "Float"
    ],
    "JavaScript": [
      "Variables",
      "Operators",
      "Functions",
      "Conditions"
    ]
  },
  "Back-end": {
    "PHP": [
      "Variables",
      "Strings",
      "Arrays"
    ],
    "SQL": [
      "SELECT",
      "UPDATE",
      "DELETE"
    ]
  }
}

Related