I have an object (that I can change!) that looks like this:
var pageContent = {
    "contact_us":[{
        "content":"<p>Lots of content here.</p>",
        "title":"Contact Us"
     }],
    "index":[{
        "content":"<p>Some other content here.</p>",
        "title":"Home Page"
     }],
    "gallery":[{
        "content":"<p>Some mo开发者_JAVA技巧re content</p>",
        "title":"Gallery"
     }],
 }
To access properties, I'm doing this:
pageContent.gallery[0]['title'];
To get the value "Gallery".
What I want to do is something like this:
var newPage = "gallery";
pageContent.newpage[0]['title'];
But, obviously that fails. How can I do what I want? Changes to anything are welcome, nothing is set in stone here.
You can use square bracket notation, like this:
var title = pageContent[newpage][0]['title'];
 
         
                                         
                                         
                                         
                                        ![Interactive visualization of a graph in python [closed]](https://www.devze.com/res/2023/04-10/09/92d32fe8c0d22fb96bd6f6e8b7d1f457.gif) 
                                         
                                         
                                         
                                         加载中,请稍侯......
 加载中,请稍侯......
      
精彩评论