To stop a for loop early in JavaScript, you use break:

const remSize = [];
let remData;

/* ...I assume there's code here putting entries in `remSize` and assigning something to `remData`... */

let remIndex = -1; // Set a default if we don't find it
for (let i = 0; i < remSize.length; i++) {      
     // I'm looking for the index i, when the condition is true
     if (remSize[i].size === remData.size) {
          remIndex = i;
          break;       // <=== breaks out of the loop early
     }
}

That said, for this specific use case, you can use Array's findIndex (to find the entry's index) or find (to find the entry itself):

const remIndex = remSize.findIndex((entry) => entry.size === remData.size);

find stops the first time the callback returns a truthy value, returning the element that the callback returned the truthy value for (returns undefined if the callback never returns a truthy value):

const remEntry = remSize.find((entry) => entry.size === remData.size);

findIndex does the same thing, but returns the index of the entry the callback returned a truthy value for or -1 if it never does.

(There's also some function, but it wouldn't be appropriate here.)

More about looping in my other answer here.

Answer from T.J. Crowder on Stack Overflow
🌐
W3Schools
w3schools.com › js › js_break.asp
JavaScript Break
Terminate the loop (break the loop) when the loop counter (i) is 3: for (let i = 0; i < 10; i++) { if (i === 3) { break; } text += "The number is " + i + "<br>"; } Try it Yourself » · You have already seen the break statement used in an earlier ...
Discussions

How can i stop for/loop if met condition
Hello Everyone! I have list array , I want to display it by Line, Line A1 on the left, line A2 is shown on the right and when the “box_pos” of A1 and A2> 4, I want to show 4 items A1 on the left and 4 items A2 on the rig… More on forum.freecodecamp.org
🌐 forum.freecodecamp.org
1
0
December 18, 2020
How do I end a For or While loop without using break?
A for loop ends when it exhausts its iterable, and a while loop terminates when its condition is no longer met. If you were going to write while True: if some_variable == "some value": break #do stuff then instead you could write: while some_variable != "some value": #do stuff More on reddit.com
🌐 r/learnpython
4
4
March 19, 2022
How do I break out of a function while in a forEach loop?
Others have answered directly, but this is not the best practice. Consider doing the following : const isChecked = [...allHovered].some(node => node.classList.contains("checked")) More on reddit.com
🌐 r/learnjavascript
13
13
August 18, 2022
Is there a way to exit a forEach loop early?
Some people will do literally anything to avoid learning to use simple built-in array methods. This problem would be solved simply and declaratively by using Array.prototype.find(). More on reddit.com
🌐 r/learnjavascript
18
7
August 2, 2019
🌐
Mozilla
developer.mozilla.org › en-US › docs › Web › JavaScript › Guide › Loops_and_iteration
Loops and iteration - JavaScript | MDN
For example, you can use a label to identify a loop, and then use the break or continue statements to indicate whether a program should interrupt the loop or continue its execution. The syntax of the labeled statement looks like the following: ... The value of label may be any JavaScript identifier ...
🌐
freeCodeCamp
forum.freecodecamp.org › javascript
How can i stop for/loop if met condition - JavaScript - The freeCodeCamp Forum
December 18, 2020 - Hello Everyone! I have list array , I want to display it by Line, Line A1 on the left, line A2 is shown on the right and when the “box_pos” of A1 and A2> 4, I want to show 4 items A1 on the left and 4 items A2 on the rig…
🌐
Udacity
udacity.com › blog › 2021 › 06 › javascript-break-and-continue.html
Exiting Loops with Javascript Break and Javascript Continue | Udacity
June 8, 2021 - While loops exit when they reach the end condition, but there may be circumstances where the looping needs to be halted immediately. A break keyword wrapped in a Javascript if statement ends the loop:
Find elsewhere
🌐
Futurestud.io
futurestud.io › tutorials › how-to-exit-and-stop-a-for-loop-in-javascript-and-node-js
How to Exit and Stop a for Loop in JavaScript and Node.js
April 15, 2021 - ... The break statement terminates an active loop and proceeds your code with statements following the loop: const users = [ { id: 1, name: 'Marcus' }, { id: 2, name: 'Norman' }, { id: 3, name: 'Christian' } ] for (const user of users) { if (user.id === 2) { break // exits the loop early } ...
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Statements › break
break - JavaScript | MDN
The break statement terminates the current loop or switch statement and transfers program control to the statement following the terminated statement. It can also be used to jump past a labeled statement when used within that labeled statement.
🌐
Hyperskill
hyperskill.org › university › javascript › javascript-break-and-continue
JavaScript Break and Continue
July 18, 2024 - Break: Exits a loop prematurely when a specific condition is met. Continue: Skips the current iteration and moves to the next one. Both statements help improve the efficiency and readability of code by allowing developers to control loop execution strategically.
🌐
LaunchCode
education.launchcode.org › intro-to-professional-web-dev › chapters › loops › terminating-loops.html
9.7. Terminating a Loop With break — Introduction to Professional Web Development in JavaScript documentation
JavaScript, like most programming languages, provides a mechanism for terminating a loop before it would complete otherwise. The break keyword, when used within a loop, will immediately terminate the execution of any loop.
🌐
W3Schools
w3schools.com › jsref › jsref_break.asp
JavaScript break Statement
// The first for loop is labeled "Loop1" Loop1: for (let i = 0; i < 3; i++) { // The second for loop is labeled "Loop2" Loop2: for (let i = 10; i < 15; i++) { if (i === 12) break Loop1; } } Try it Yourself » · JavaScript Tutorial: JavaScript Break and Continue
🌐
GeeksforGeeks
geeksforgeeks.org › javascript › javascript-break-and-continue
JavaScript Break and Continue - GeeksforGeeks
February 12, 2025 - The break, continue, and label statements are powerful tools for controlling loop execution in JavaScript. Use break when you need to exit a loop entirely.
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Statements › for
for - JavaScript | MDN
The result of this expression is discarded. ... An expression to be evaluated before each loop iteration. If this expression evaluates to true, statement is executed. If the expression evaluates to false, execution exits the loop and goes to the first statement after the for construct.
🌐
Medium
medium.com › @rahul.jindal57 › break-continue-and-label-in-javascript-loop-9dc6124afa8
break, continue and label in Javascript loop | by Rahul Jindal | Medium
July 2, 2022 - We can do all this with the help of following:- To break out from the current loop we use break keyword, If we are working with while loop or do while loop, loop exits when a condition becomes falsy, but we can make loop force exit with the ...
🌐
Mastering JS
masteringjs.io › tutorials › fundamentals › foreach-break
How to Break Out of a JavaScript forEach() Loop - Mastering JS
October 5, 2020 - The forEach() function respects changes to the array's length property. So you can force forEach() to break out of the loop early by overwriting the array's length property as shown below.
🌐
TechOnTheNet
techonthenet.com › js › break.php
JavaScript: Break Statement
If there are nested loops, the break statement will terminate the innermost loop. You can also use the break statement to terminate a switch statement or a labeled statement. Let's look at an example that shows how to use a break statement in JavaScript. You can use the break statement with ...
🌐
Built In
builtin.com › articles › javascript-foreach-break
How to Stop a JavaScript ForEach Loop | Built In
Even in this custom-built, shiny new forEachButWithStyle, there’s no emergency exit. It’s like a merry-go-round that’s lost its off switch. Just when you thought forEach was the marathon runner of JavaScript, never stopping for a break, I discovered a sneaky little trick. Picture this: a forEach loop, prancing around like it owns the place, and then suddenly, we throw an error, and it's like hitting the emergency stop button on a runaway carousel.
🌐
Programiz
programiz.com › javascript › break-statement
JavaScript break Statement (with Examples)
When break outerloop; is encountered, it exits the outer loop, and control shifts to the statements following it. Let's look at an example. outerloop: for (let i = 1; i <= 3; i++) { innerloop: for (let j = 1; j <= 3; j++) {