score:3
Accepted answer
yearsvalue
is a string and therefore using json.stringify
won't help you.
also, render
method must return something:
constructor (props) {
super(props);
this.state = {
selectvalue: '',
yearsvalue: [],
months:''
}
this.setdatagroup = this.setdatagroup.bind(this);
}
...
render() {
const { yearsvalue } = this.state
return (
<div>
{yearsvalue.map((item, index) =>
<div key={index}>{item.data}:{item.value}</div>
)}
</div>
}
}
score:2
your data is in correct format. initialize yearsvalue
as array in constructor
like
this.state = {
yearsvalue: []
}
and then you can use yearsvalue
state in render
like below
render() {
return (
<div>
{this.state.yearsvalue.map((d, index) => {
return (
<div key={index}>{d.data}</div>
)
})}
</div>
)
}
Source: stackoverflow.com
Related Query
- looping the array of json object in reactjs
- Iterate through a nested json object array in the render (ReactJS)
- Looping through a JSON array with ReactJS, but not understanding how the code actually works
- How to display the content of an array inside an object in Reactjs
- ReactJS nested looping on JSON object
- Trying to store json object array in state, then map the items into render
- How to pass the values to point json object in ReactJs
- Reduce JSON object containing JSON objects into an array of the form [Path, Value]
- Reducing the size of a JSON object array by stripping unwanted object attributes
- How to iterate through the array inside json object
- Can't access value from an array inside JSON object in Reactjs
- ReactJs App's mapped list of buttons from Json file only have the last value of json array
- Change the state input which is a JSON Object that is present inside an array of JSON
- reactJS state array of objects - how do I reference the state array object in setState()
- reactjs calculate sum of all the value present in state in a form of array of object
- Get API Json data in object and array format using redux and reactjs
- Does assigning a JSON object to the style attribute in ReactJS make the object non-configurable
- Reactjs Ajax returns first empty array while getting json object
- How to print json object array to print all the values as category and subcategory
- How to prepend a value to an array inside the object of state in Reactjs
- Reactjs : Adding element to array object in Json
- Display a json array of object in ReactJS
- ReactJS How to update the state in object which is in the array
- Reactjs how to display data from nested json object within the same html code
- How to get the data from array object in JSON API? (React.js)
- show the seats from an object array Reactjs
- ReactJS create array from json object for select option
- Looping through array of objects and return the key and value for each object
- Merge keys in JSON object to return an array of merged keys and the value with Javascript
- Is there a way to send a object instead of array to the Back-End ? - ReactJS
More Query from same tag
- Laravel post request send 302
- Reset form inputs after submit
- Using createjs-soundjs in react web app
- Graphql query returning 10 digit number instead of query data
- "Must use destructuring state assignment": How to destructure from object and place on property inside object literal
- Is it possible to check prop types as case insensitive on React prop-types?
- Open a div element on a button click with ReactJS
- render() is not being called on this.setState()
- Doing curl POST request as an npm script
- A state mutation was detected between dispatches, Redux toolkit and selectors/reselect
- How to get Keys and values of a JSON object in React.js
- how to get spesific data from api with axios and react js?
- How to set custom date to DatePicker of react-datepicker using MomentJS?
- Posting with axios keeps returning Request failed with status code 422
- Node JS Using Bcrypt.Hash- Password does not get hashed after updating
- Using ReactJS to render components within Aurelia
- React input placeholder - type-writer animation?
- Handling errors of undefined URLs
- Form not clickable until setInterval has been cleared in React useEffect
- i can't display pdf file getting from server in new window
- Create a React componenent by grouping an array by index range in JS
- How do I set a state and revert it back to the previous state
- Call a method in child component only after parent completes re-render
- React in CSS with react in viewport
- How do I stub Ant Design's Form getFieldDecorator()?
- React.useCallback : it doesn't prevent continuos re-rendering
- How to set media queries with jest?
- How to access baseUrl method from axios in react?
- Passing current input value to parent compnent
- Using history.push() while using a component within another component