Exploring nested arrays within JSON objects - techniques for accessing specific properties

Having some difficulty with the JSON data I received. The structure is as follows:

[
[
    {
        "items": [
            {
                "id": "xxxxxxx",
                "name": "xxxxxxxxxx",
                "description": "xxxxxxxxxxx"
            },
            {
                "id": "xxxxxxx",
                "name": "xxxxxxxxxx",
                "description": "xxxxxxxxxxx"
            }
        ],
        "parentId": "xxxxxxxx",
        "title": "xxxxxxxxx",
        "type": "xxxxxxx"
    }
],
[
    {
        "items": [
            {
                "id": "xxxxxxx",
                "name": "xxxxxxxxxx",
                "description": "xxxxxxxxxxx"
            },
            {
                "id": "xxxxxxx",
                "name": "xxxxxxxxxx",
                "description": "xxxxxxxxxxx"
            }
        ],
        "parentId": "xxxxxxxx",
        "title": "xxxxxxxxx",
        "type": "xxxxxxx"
    }
]
]

I have an object called 'data', and when I stringify 'data', I get the structure above. My challenge is locating a specific parentId within this JSON. The current structure differs from what I am used to, as I am accustomed to having 'items' at the top level for easier navigation.

Answer №1

for(let count=0;count<dataList.length;count++)
{if(dataList[count][0].parentId=='parentIdentifier')
//processing
}

Answer №2

If you're interested in utilizing a library, you have the option to achieve this using Underscore.

Here is how you can accomplish it:

_(data).findWhere({parentId: idToLookUp});

This code snippet will retrieve the object from an array where the parentId matches the idToLookUp.

Check out this Fiddle for a demonstration.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

What is the best way to sum up array elements until they equal a target number, and then create objects using these summed values?

Suppose I have an array containing 5 different values for width, with a maximum width of 6 that needs to be reached. How can I iterate through the array and construct an object with those values each time it hits the maximum value without exceeding it? Le ...

Three.js experiencing issues with FBX animations running erratically

Having trouble with animations on some fbx models. When an animation lasts 20 seconds, the model remains stationary for 19 seconds and then suddenly moves within the last second or so. However, other fbx models animate correctly. The code used to run the a ...

Unexpected behavior from Bootstrap within React

I recently started working on a React project that I initiated with the create-react-app command. To incorporate Bootstrap into my project, I added the necessary CDNs to the public/index.html file after generating the project. <link rel="stylesheet" hr ...

Leveraging the power of React's callback ref in conjunction with a

I'm currently working on updating our Checkbox react component to support the indeterminate state while also making sure it properly forwards refs. The existing checkbox component already uses a callback ref internally to handle the indeterminate prop ...

"Transitioning from jQuery to Vanilla Javascript: Mastering Scroll Animations

I'm seeking guidance on how to convert this jQuery code into pure Javascript. $('.revealedBox').each(function() { if ($(window).scrollTop() + $(window).height() > $(this).offset().top + $(this).outerHeight()) { $(this).addCla ...

Tips for executing multiple asynchronous calls simultaneously within a nested map function

I am facing a scenario where I have an object with nested arrays of objects which in turn contain another set of nested arrays. To validate these structures, I have an asynchronous function that needs to be executed concurrently while awaiting the results ...

Vuex is throwing a mysterious ReferenceError that is leaving developers

Currently, I am developing a Single Page Application (SPA) using Vue.js and Vuex. Within this project, I have set up some data in the store and displayed it in a child component. This child component includes radio buttons that trigger a function called ge ...

AJAX requests sent from different origins to AWS S3 may encounter CORS errors on occasion

My current objective is to access publicly available files stored in S3. The CORS configuration for my S3 setup is as follows: <?xml version="1.0" encoding="UTF-8"?> <CORSConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/"> < ...

Tips for successfully sending an array of arrays with jQuery ajax

I have an array in PHP that looks like this: $treearr = array( array("root","search","Search",false,"xpLens.gif"), array("root","hometab","Home Tab",false,"home.gif"), array("root","stafftab","Staff Tab",false,"person.gif"), array ("stafftab","new ...

Array updating using the foreach method in Angular

Hey everyone, I've encountered an error that seems to be related to scope and I could use some advice. I'm currently looping through an array and trying to push the results to another array. However, when I attempt to push the results to public m ...

Looking for assistance in incorporating a date stamp into an Excel formula

Is there a way to add a current date timestamp mm/dd/yy at the end of an array formula instead of manually changing it every time? The formula I have includes J2, L2, O2, and N2. Here is the formula: =J2&" "&L2&" "&O2&" "&N2&" ...

Using JS and d3.js to eliminate or combine duplicate connections in a d3.js node diagram

Hey there! Hello, I am new to working with js/d3.js and tackling a small project. Here are some of my previous inquiries: D3.js: Dynamically create source and target based on identical JSON values JS / d3.js: Steps for highlighting adjacent links My cu ...

Incorporating useState into React Native navigation screens to dynamically update FlatList items

I'm working on implementing react-navigation to pass and update useState between screens in order to render a flatlist. The issue I am facing is that the flatlist updates correctly when I navigate back to the previous screen and then return to the com ...

Is there a specific side effect that warrants creating a new Subscription?

Recently, I had a discussion on Stack Overflow regarding RxJS and the best approach for handling subscriptions in a reactive application. The debate was whether it's better to create a subscription for each specific side effect or minimize subscriptio ...

The Navbar's Toggle Icon Causes Automatic Window Resize

I implemented a mobile navigation bar using React and JS that slides in from the left when clicked. However, I encountered two issues: whenever I click on a menu button in the navbar or when my ad carousel moves, the window resizes for some reason. Additio ...

Checking the authenticity of trello board API responses with Python unittest

My current task involves writing a unittest that interacts with the Trello board API to validate the presence of a specific card. Initially, I attempted to use the /1/boards/[board_id]/lists endpoint to retrieve data in the following format: [{'card ...

how to change the color of a specific item in a list created using v-for

I'm a beginner when it comes to vueJs and I'm attempting to toggle the class "active" on a single element once it has been clicked. Currently, my code toggles all elements with the class material_icons. How can I modify it to toggle only the elem ...

Sending information to a subpage through props using a query in the URL triggers a 431 Request Header Fields Too Large error

I have a page called campaigns, and I am facing an issue on the index page where I want to pass data to my dynamic page [campaignId].tsx. Although I can see the data on my dynamic page, the URL links are becoming too long, leading to an HTTP Status code 4 ...

I have experimented with both POST and GET methods in Node.js, exploring a variety

After creating a login page with a GET form, the server code includes: app.use(express.static(path.join(__dirname, 'public'))); I am facing an issue trying to implement a POST request. When I use "POST", it gives me a "CANNOT / PO ...

Error: The object does not contain the specified method

After deploying a web app to a remote host, I encountered an unusual error. Uncaught TypeError: Object #<error> has no method 'endsWith' Key Information: The application functions perfectly on my local machine as the host. The error ari ...