-1
this.state = { glasses :[{id:0,,value:100, show:true,},
                            {id:1,,value:150, show:false},
                            {id:2, value:200, show:true,},
                            {id:3, value:300, show:false,} .  ]
}

I have this data in states. I need to iterate this state through map and If i encounter show:true, it should stop iteration. like it breaks out of map function. Any help would be appreciated.

  • Does this answer your question? [Break statement in javascript array map method](https://stackoverflow.com/questions/12260529/break-statement-in-javascript-array-map-method) – kaya3 Mar 20 '20 at 12:47
  • if you want to break out of iteration you should use a for-loop or forEach for that, not map. – Michael Mar 20 '20 at 13:13

1 Answers1

2

Why don't you use a for-loop instead?

I am suggesting it because seems it isn't possible to use break on map. A similar question was ask here: Break statement in javascript array map method

TheMaysk
  • 21
  • 2