cell(numX, numY) { this.cells.map((cell) => { if (numX == cell.opts.numX && numY == cell.opts.numY) { console.log(cell); return cell; } }); } The code above definitely finds the necessary Cell (since console.log () prints what is needed). But return does not return this value. For me it remains unclear why the code below works as it should, but this code does not want to work. Please explain .
cell(numX, numY) { let xcell; this.cells.map((cell) => { if (numX == cell.opts.numX && numY == cell.opts.numY) { console.log(cell); xcell = cell; return; } return; }); return xcell; } By the way, I would like to add. It is necessary for me that when the necessary element is found, it would immediately return without forcing the cycle to go to the end (it is known that only one element can be found). Here the fact is that the search will be performed on a fairly large number of elements, and there is no need for extra checks here. Therefore, as soon as an item is found, you need to return it immediately. And Debug-Console in Chrome shows me that even after the element was found and the return worked, the cycle continues to run in search of other elements, which is fundamentally wrong, because return must not only return a value, but also stop the execution of the block in which he is (as far as I know).