I have to break the forEach method when the value of available is true.
JavaScript
x
20
20
1
[
2
{
3
"Book": "Book1",
4
"available": false
5
},
6
{
7
"Book": "Book2",
8
"available": false
9
},
10
{
11
"Book": "Book3",
12
"available": true
13
},
14
{
15
"Book": "Book4",
16
"available": true
17
}
18
]
19
20
And print only one item after the value of available comes true.
Advertisement
Answer
ForEach doen’s support break. use for of
JavaScript
1
6
1
for (const el of arr) {
2
if (el.available) {
3
break;
4
}
5
}
6