score:1
Loop through the array like, and call it by their index like the example below
let layout= [
[
{
type: 'text',
value: 'abc'
}
],
[
{
type: 'text',
value: 'def'
}
],
[
{
type: 'text',
value: '123'
},
{}
]
];
let rows = [];
var div = document.createElement('div');
for (let i = 0; i < layout.length; i++) {
rows.push('<div className="row" key={i}></div>');
var s = '<li>'+layout[i][0].type+': '+layout[i][0].value+'</li>';
document.body.innerHTML +=s;
}
score:0
In your for
loop, you get a number to work with. In this case, i
. You can access the contents of i
with layout[i]
. Push that to your rows
object inside the div
, that should work.
score:0
JS Fiddle Demo React Solution
<div>{(layout).map(function(data){
return(
data.map(function(data){
return(
<div>
{data.type+
"\n"
+data.value
}
</div>
)
})
)
})}</div>
score:0
I suggest that you use Array.map:
layout.map(row => {
return (
<div>
<input type={row.type} value={row.value} />
</div>
)
})
For a complete example with React, see : https://jsfiddle.net/gbourgin/wu737LLj/
Remark: I don't see why you need an array of array for your layout variable
Source: stackoverflow.com
Related Query
- How to loop through an array and display data within the object of that array, in react and javascript
- Loop through Array of object with the same data on some object and get it displayed once
- Loop through json object and display the data with React?
- How can I toggle the display of an array that is located within each object of another array that comes from an API?
- How to map through an Array of object with the same data on some object and get it displayed once and also get other properties
- How to loop through an object with key and associated array and filter the array based on value presence in another array
- Fetched data from external api,how to loop through the array and display values
- Loop through array and render multiple instances of a child component with that data with React?
- How do I take an array of objects and reduce it so that data at a repeated object key is combined?
- How to display and handle dynamic checkoxes that are dependent on Task array value in the backend (Mongodb) in react js?
- how to display and map the first id of an state or const data array objects?
- How to loop through an array of strings backwards x amount of times and start over when the end is reached?
- Loop through array of objects, check for a matching parameter and add the matching object to new array
- How to compare each elements in an Array and group the ones that have same data (in my case date) ? JavaScript
- How to loop an object that is inside an array and is inside an object? React
- How do I map an through an array of objects and display each object individually? I want each pizza order to show
- How can loop through array of JSON Object to find property value that includes user input characters
- In React How can I fetch data and render a single object in a states array without mapping the whole thing?
- How can I break through React maps to display object that has two values one with an array other with string or number(result)
- How to check and return value of state object array and use that to identify which object to take data from
- How can I loop through a collection of data and return the entire object?
- how to loop through data and assign values to state array in react
- How to destructure an array within an object and rename the variables created from it?
- Loop object that in the array and in the another object
- How to access the value inside array of object within that array
- How can I group specific items within an object in the same array and delete them from the core array?
- Reactjs how to display data from nested json object within the same html code
- How to loop through and display buttons that have an onClick and pass a different variable to another function?
- How to iterate with Object Dot Keys and Array Dot Map to display data in a component?
- I'm trying to delete an object from an array and the response I get is that the data is undefined
More Query from same tag
- I want to run Graphql Apollo query with as many ids as possible
- why do we need to put the onViewableItemsChanged prop inside a useRef hook in react native
- How to use a prop to form an image url
- How to use PayPal's Express In-Context Checkout with ReactJS?
- Receive error when deploy to GitHub pages
- How to make card component align in one row (React)
- How to getById in redux
- How to simulate/test key press using Jest?
- How to checddsa hooks?
- TableHeader of Material UI does not make the content bold
- el.getBoundingClientRect is not a function in react odometer js with react visibility sensor?
- How do you encode a file to base64 then upload as multipart file to backend api using JS?
- Typescript: How would I convert PropTypes.oneOf(Object.value(FOOBAR)) to a type?
- How to dynamically append more information to a useState Array in React
- ReactJs componentDidMount executes twice
- Why infinite-scroll in react don't see data from function map()?
- Reconnecting to socket channel after disconnection in react
- GraphQL and GatsbyJS: my query isn't working in layouts folder
- Simple way to get value from DropDown menu in ReactJS
- React - Display new component when form is submitted
- React test onchange dom not updating?
- Comma separated email validation using Yup
- Search form with ability to share the URL in ReactJs
- Losing key value pair in react when mapping over props
- React custom hooks value is not changed
- How to find a value of array inside another array then set data accordingly?
- Handling number input with Redux Form does strange things
- How execute a Java function from a Constructor of React component throuhg webview
- React.js - Using one component multiple times with different settings
- GAE files blocked due to mimetype/unknown url handler type for js files with multiple .'s