当前位置:网站首页>JS (foreach) return cannot end the function solution
JS (foreach) return cannot end the function solution
2022-07-29 05:10:00 【nianyuw】
js(forEach) appear return The solution to the function cannot be ended
Someone asked a question today ,return It means to end directly ( End ) Function ? I said yes. , He asked me a question

He's here return It doesn't end the function as we think , The code continues to execute downward

I went to Du Niang to study , Found in js The function cannot be called as a whole in multiple layers return
Solution 1 :
Let's start with a flexible method ( Throw an exception in the code area that needs to be stopped , You can stop the code )

throw console.info(' Content ');
throw " Content ";
Solution 2 :
stay forEach in , perform return Cannot end the entire method (forEach The traversal cannot be terminated before all elements are passed to the called function )
Switch to for loop , perform return Can solve
边栏推荐
- How is the entered query SQL statement executed?
- pytorch学习笔记
- 关于thymeleaf的配置与使用
- Unity metaverse (III), protobuf & socket realize multi person online
- Solution | get the relevant information about the current employees' highest salary in each department |
- sql日志
- Let you understand several common traffic exposure schemes in kubernetes cluster
- 2021-11-02
- Climbing the pit of traffic flow prediction (II): the simplest LSTM predicts traffic flow using tensorflow2
- Apache POI实现Excel导入读取数据和写入数据并导出
猜你喜欢

Diagram of odoo development tutorial

< El table column> place multiple pictures

Quick start JDBC

office2010每次打开都要配置进度怎么解决?

What if the office prompts that the system configuration cannot run?

Understand activity workflow

【微信小程序--解决display:flex最后一行对齐问题。(不连续排列会分到两边)】

SparkSql批量插入或更新,保存数据到Mysql中
![[untitled]](/img/04/242e85ee8eea5bd6ae8144fc048241.png)
[untitled]
带你搞懂 Kubernetes 集群中几种常见的流量暴露方案
随机推荐
WPS insert hyperlink cannot be opened. What should I do if I prompt "unable to open the specified file"!
MySQL regularly calls preset functions to complete data update
Jackson解析JSON详细教程
Wps如何使用智能填充快速填充数据?Wps快速填充数据的方法
Improve the readability of your regular expressions a hundred times
2021-10-11
MySQL time calculation function
Mysql把查询到的结果集按指定顺寻进行排序
How does word view document modification traces? How word views document modification traces
Force deduction ----- sort odd and even subscripts respectively
如何让照片中的人物笑起来?HMS Core视频编辑服务一键微笑功能,让人物笑容更自然
Deadlock analysis using jstack, jconsole, and jvisualvm
虚拟偶像的歌声原来是这样生成的!
Diagram of odoo development tutorial
Operator operation list of spark
How does WPS use smart fill to quickly fill data? WPS method of quickly filling data
WPS如何进行快速截屏?WPS快速截屏的方法
DataSourceClosedException: dataSource already closed at Mon Oct 25 16:55:48 CST 2021
Traffic flow prediction pit climbing record (I): traffic flow data set, original data
ODOO开发教程之透视表