reactjs - React loop over an object with array -
data = [ { "2017-08-09": [ "09:00", "09:30", "10:00", "10:30", "11:00", "11:30", "13:00", "13:30", "14:00", "14:30", "15:00", "15:30", "16:00", "16:30" ] } ]
i'm trying map on array of objects , display info follows:
date 2017-08-09 available hours 09:00 09:30 10:00 ...
i'm having trouble looping on data structure,
i've updated link. did not use lodash, nested map()
calls. first map through initial array, , within each object grab keys of object. after that, map through keys of object, , 1 last map()
through times of each date.
you can refer below code:
const data = [ { "2017-08-09": [ "09:00", "09:30", "10:00", "10:30", "11:00", "11:30", "13:00", "13:30", "14:00", "14:30", "15:00", "15:30", "16:00", "16:30" ] } ]; class app extends react.component { render() { return ( <div> <h2>js map</h2> { data.map(item => { return object.keys(item).map(date => { return ( <div> <h1>{date}</h1> {item[date].map(time => { return <h3>{time}</h3> })} </div> ) }) }) } </div> ); } } reactdom.render(<app />, document.getelementbyid("root"));
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.1.0/react.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.1.0/react-dom.min.js"></script> <div id="root"></div>
Comments
Post a Comment