0

I have a array of objects

    [{
    "id": 1,
    "name": "aaa"
}, {
    "id": 2,
    "name": "bbb"
}, {
    "id": 3,
    "name": "ccc"
}]

and i have a checkbox element,which is kind of iterating based on the json length

<input type="checkbox" onClick={(e)=>this.props.handleChange(e)} selected={something to figureout} />

issue am facing is when i click on checkbox,it will passing the data and it will be storing inside some array,say am passing 2nd and 3rd object and its storing some other array.So on what basis user will be understanding 2 and 3 are selected.

For that selected attribute in checkbox element should be true (for that one condition check should be there which will evaluvate its true or false)

Note: i have the selected array handy which have the id also json iteration ,which also have id so something am looking like this

   <input type="checkbox" onClick={(e)=>this.props.handleChange(e)} selected={selectedArray.id===data.id} /> 

-> will work fine if we going with radio,but here its checkbox

but it wont work ,since we are using checkbox, it should be like whether data.id is included in new array json object.

Hope its clears

midhun k
  • 546
  • 1
  • 12
  • 28
  • 1
    That's not a "JSON array". That's an array of objects. -> [What is the difference between JSON and Object Literal Notation?](https://stackoverflow.com/questions/2904131/what-is-the-difference-between-json-and-object-literal-notation) – Andreas Mar 26 '20 at 15:03
  • Does this answer your question?https://stackoverflow.com/a/60773178/11872246 – keikai Mar 26 '20 at 15:57

0 Answers0