showcasing every element from a multi-layered array within its own separate div using JavaScript

Is it possible to loop through a multidimensional array made up of 9 arrays with 9 elements each and display each item in a separate div? I want each div to contain one array item.

Here's the code I have been working on: Link to my approach

Answer №1

Discover the method to access all elements within a multidimensional array.
Utilize the straightforward .length function along with for loops.

 let myArray = [{"child": ["one", "two", "three", "four"]}, 
                   {"child": ["five", "six", "seven", "eight"]}];

    for(let i = 0; i < myArray.length; i++){

       let childArray = myArray[i].child;

       for(let j = 0; j < childArray.length; j++){

      console.log(childArray[j]);

       }

    }

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 methods are available for transferring information between nodejs and puppeteer?

Recently, I developed a nodejs application that kicks off from index.js. Within index.js, puppeteer is launched and bot.js is injected into a headless-api page using the addScriptTag function. In my implementation, index.js sets a cookie to pass initial v ...

Is there a way to identify and count duplicate data-items within an array, and then showcase this information using a react view?

If we have an array like this: [{id: 1, name: "chocolate bar"}, {id:2, name: "Gummy worms"}, {id:3, name:"chocolate bar"}] Is there a way to show on the dom that we have "2 chocolate bars and 1 Gummy Worms"? ...

Internet Explorer IE 11 encounters an "Error: Object does not support property or method" issue

Recently, I started using the jquery circleChart.min.js plugin for creating a circle chart. It's been working perfectly on all browsers except for Internet Explorer 11 (IE11). I keep getting an error message when trying to run it in IE11. Can anyone h ...

Is it possible for the Vue.js application to show the component right where the cursor is located in the textarea?

I am looking to create a Vue.js component with the following capabilities: As the user types in the textarea, I want the component to display recommended words. For instance, if the user types the letter s, I want a dropdown list to appear with words ...

Remove objects from an array if they share identical key values

I'm having trouble getting this to work. I have an array of objects that looks like this: let myCities = [ { value: 'Barcelona', code: 02342837492482347 }, { value: 'Rome', code: 28282716171819 }, { v ...

Performing an Ajax request in JavaScript

I've encountered an issue with my jQuery ajax call. It was working perfectly fine when placed in a jQuery file. Here's the code snippet: var request = $.ajax({ url: "kscript.jsp", type: "POST", data: {st:start, sp:stop}, dataType ...

My search bar in the navbar is sticky, but unfortunately it still ends up covering the page content as you scroll down

I am trying to figure out how to prevent the search bar (not the top navigation bar) from overlapping with the page contents when scrolling down. Just to clarify, I have both a navigation bar and a search bar, but the issue I'm addressing specifically ...

Ways to inform users with a JavaScript alert before they leave the website or domain?

Is there a way to modify this code so that the alert only triggers when the user leaves the site/domain, instead of navigating to other pages within the site? window.onunload = unloadPage; function unloadPage() { alert("Hello world"); } ...

When I shift a JavaScript function from inline code to a separate JS file, I encounter the error message "function is not defined"

I am struggling to get a simple task done: <!DOCTYPE html> <html lang="en"> <head> </head> <body> <script src="js/test.js" type="text/js"></script> <button onclick="test()" type="submit">Test</button> ...

Using postMessage with an iframe is causing issues within a React application

I encountered two errors when executing the code below in my React application: try { iframe.src = applicationRoutes.href; iframe.style.width = '0px'; iframe.style.height = '0px'; iframe.style.border = '0px& ...

How to resolve undefined callback when passing it to a custom hook in React Native

I'm facing an issue with passing a callback to my custom hook: export default function useScreenshotDetection(onScreenshot) { useEffect(() => { ... onScreenshot(); ... }, []); } Strangely, the callback is not being detected ...

Storing information in the DOM: Choosing between Element value and data attribute

When it comes to storing values in a DOM element, we have options like using the data attribute. For example, $("#abc").data("item", 1) can be used to store values and then retrieve them with $("#abc").data("item"). However, I recently discovered that th ...

Bring in a 3-dimensional model using JSONLoader in three.js

I'm facing some challenges with incorporating a simple 3D object created in Maya into my Three.js project using JSONLoader. The object consists of various materials (Lambert and Phong) and different colors. I used Maya to create a .obj file, then Ble ...

Experiencing unexpected crashes, unable to determine the cause?

#include <stdio.h> #include <stdlib.h> #include <ctype.h> #include <string.h> int compare(char guess[], char secret[]) { int i=0;int bool=1; while((i<=20)&&(bool==1)) { ...

Can a Javascript function parameter be transferred to PHP?

As I understand it, PHP is used on the server-side and JavaScript is used on the client-side. However, I am curious if there is a way to achieve the following scenario. Imagine having a JavaScript function that makes an Ajax call to a PHP file. Here is an ...

Dropdown Menu with Bootstrap 4 Toggle Checkbox

Within a Bootstrap 4 dropdown menu, I integrated a checkbox styled with the Bootstrap Toggle Plugin. However, upon clicking the toggle switch, the menu abruptly closes. To address this issue, I added onclick="event.stopPropagation();" to the menu item, as ...

Inject $scope into ng-click to access its properties and methods efficiently

While I know this question has been asked before, my situation is a bit unique. <div ng-repeat="hello in hello track by $index"> <div ng-click="data($index)"> {{data}} </div> </div> $scope.data = function($index) { $scope.sweet ...

Update a portion of the list items

Here is the HTML code I am working with: <ul id="info"> <li> <span>Name:</span>Charis Spiropoulos </li> ... I need to change the content of the <li> element that is not within the span. How can I do this? Cur ...

Tips for maintaining interactivity after a page refresh

$(document).ready(function () { $("#2").click(function () { $("#content").load("{% url 'about' %}"); }); $("#3").click(function () { $("#content").load("{% url ...

Incorporate the Google Maps API into a React application

I've recently started learning react and I'm currently trying to integrate the Google Maps API into my React application. Within my app, I have a search input field and a designated area for the map located at http://localhost:8080/. My main qu ...