Retrieve Multi-Level Array

Can someone help me with returning a multidimensional array from a function? I seem to be having trouble getting it right as I want to include both key and value pairs in the array.

function Multidimensional(){

    return [ 
        "one": [
            "two":[],
            "three":[
                "testing.png":{source:"http..."}
            ],
        "another.png": {source:"http..."}
    ];
} 

Answer №1

If you're looking to store key/value pairs, the best option is to utilize an object.

function NestedData(){

    return { 
        "first": {
            "second":[],
            "third":{
                "example.jpg":{src:"http..."}
            },
        "another.jpg": {src:"http..."}
    };
} 

To retrieve the stored information, you can do the following:

var info = NestedData();
console.log(info['another.jpg']);
// or
console.log(info.first);

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

Can you explain the mechanism behind how the spread syntax (...) interacts with mapGetters?

When implementing a computed getter using the mapGetter helper from Vuex, the syntax typically involves using the spread operator in the following way: ...mapGetters([ 'getter1', 'getter2', 'etc' ]) Although th ...

What is the most effective way to capture requests in a Node.js environment using Express?

Can you provide guidance on how to capture requests in express + nodejs? I am looking to capture all requests such as /in/docs, /es/docs, /fr/docs... const server = express() server.get('/in/docs', (req, res) => { console.log('====kk ...

What's the best way to ensure images and videos in a div maintain their aspect ratio when resizing?

Is there a way to make the image and video fit inside the div without altering the aspect ratio? The code snippet below is what gets displayed on my website, utilizing bootstrap for responsiveness. <div id="micropost-208"> <di ...

Ways to designate as not defined or remove specific sections

I've been struggling for hours to figure out how to delete or set to undefined parts of the code below: $(document).ready(function() { // Generate a simple captcha function randomNumber(min, max) { return Math.floor(Math.random() * (m ...

Dragging the entire ForceDirected Graph in D3.js is not functioning

tag, I am currently working on implementing a D3 force directed graph using D3 v6 and React. The graph includes features such as zoom functionality and draggable nodes. However, as the graph can become quite complex and large due to dynamic data, I aim to ...

Populating DropdownList with JSON data

I need to build a dropdown list in my application using data from a json file. For example, I have countries.json, states.json, and cities.json files in my application. [{"label":"US Dollars (USD)","country":"US","value": "USD"},"label":"CA Dollars (CAD)" ...

Unlocking the power of dynamic stacking and unstacking in bar charts using chart.js

Looking to customize a barchart to toggle between stacked bars and bars behind each other? Keep in mind that the x-axes should be stacked behind each other. useEffect(() => { if (!myChart) return; if (barStack) { ...

How can I retrieve the mouse click coordinates on an image using JavaScript?

Currently facing an issue with the code provided below for retrieving x/y coordinates in JavaScript. I am working on creating a color picker using an image. The objective is to display a color window and cancel button when a user clicks on the pick color ...

Omit any items from an array that do not have any child elements

Upon receiving data from the server in the format of a flat tree, I proceed to transfer this data to the JsTree library for tree building. Before sending the data to JsTree, I filter out any empty elements of type "folder" that do not have children. Below ...

Using HTML within a JSON string in Java

I need to save the contents of a Java class called MyClass into a text file using JSON for encoding, instead of implementing the Serializable interface. I plan to utilize Google's Gson library, specifically the JsonWriter class. The structure of the M ...

"The authentication scheme is unrecognized" - this is the message produced by Node-LinkedIn module

I am currently utilizing the node-linkedin npm package to authenticate and retrieve information about other users, such as their name, job title, company name, profile picture, and shared connections. While I am able to successfully receive and store the a ...

Guide to rounding values retrieved from JSON object using Math.round in Vue.js

I'm currently working on a Vue 3 component using the Composition API that fetches values from a JSON object and displays them on the screen. The component reads data from a local data.json file and returns these values to the template. The JSON file c ...

Is it possible for Javascript to detect your IP address?

Question About Getting Client IP Address: Get Client IP using just Javascript? I am aware that PHP can retrieve the client's IP address using <?php echo $_SERVER['REMOTE_ADDR']; ?> Is there a way for JavaScript to accomplish the ...

Creating a route provider tailored to specific user roles

I have a rather straightforward requirement. There are 3 different User Roles: CATUSER LICUSER ALLUSER The User Role value is stored in the $rootScope.userRole variable. The User Role is predefined before the AngularJS application starts as the Angula ...

The JS content failed to load into the HTML page

I need help creating a workout tracker using two JS files. The main.js file is responsible for loading content from the second file (workoutTracker.js) into the index.html. However, I'm facing an issue where the content is not being displayed on the p ...

Modifying HTML elements with JavaScript - a practical guide

I'm trying to dynamically add the variable x to an existing HTML tag. The goal is to update the image tag <img id="Img" src="IMG/.jpg"/> by appending the variable x at the end of its id and source: <script> var images ...

What is the best way to access the EXIF data of an image (JPG, JPEG, PNG) using node.js?

In my quest to access the EXIF data of an image in order to extract GPS information such as Latitude and Longitude, I have experimented with approximately 4-5 EXIF packages available on npm/node, including exif, exif-parser, node-exif, exifr, exif-js, and ...

What is the best approach for creating a Pagination component in React JS?

I recently started developing a web-app and I'm still learning about web development. I have received a backend response in JSON format with pagination information included: { "count": 16, "next": "http://localhost:800 ...

Creating a modal form with jQuery in ASP.NET

I'm fairly new to ASP.NET development and have been able to work on simple tasks so far. However, I now have a more complex requirement that I'm struggling with. My goal is to create a modal form that pops up when a button is clicked in order to ...

Despite declaring a default export, the code does not include one

Software decays over time. After making a small modification to a GitHub project that was three years old, the rebuild failed due to automatic security patches. I managed to fix everything except for an issue with a default import. The specific error mess ...