当前位置:网站首页>[js] basic syntax - for loop
[js] basic syntax - for loop
2022-07-05 13:49:00 【Weichi Begonia】
Array , Map and Set The cycle of : for of / forEach
The loop of objects : for in
Array of for loop – for (… of … ) / forEach / for (var i=0; i< length ; i++)
var a = [1,2,3,4,5]; for (var each of a){ console.log(each); }var a = [1,2,3,4,5]; a.forEach(function (element){ console.log(element); })var a = [1,2,3,4,5]; for (var i=0; i<a.length; i++){ console.log(a[i]); }
Object's for loop – for (… in …) {…}
var obj1 = { 'a':1, 'b':2, 'c':3}; for (var key in obj1){ console.log(key, obj1[key]); }
Map and Set Of for loop – for ( … of …) / forEach()
var m = new Map([['a', 1], ['b',2], ['c', 3]]) for (var element of m){ console.log(element[0], element[1]); }
var m = new Map([['a', 1], ['b',2], ['c', 3]]) m.forEach(function (value, key, map){ console.log(key, value); })
var s = new Set([1,2,3,4,5]); s.forEach(function (element){ console.log(element); })
边栏推荐
- 53. Maximum subarray sum: give you an integer array num, please find a continuous subarray with the maximum sum (the subarray contains at least one element) and return its maximum sum.
- Idea set method annotation and class annotation
- PostgreSQL Usage Summary (PIT)
- FPGA learning notes: vivado 2019.1 add IP MicroBlaze
- Operational research 68 | the latest impact factors in 2022 were officially released. Changes in journals in the field of rapid care
- 龙芯派2代烧写PMON和重装系统
- Flutter 3.0更新后如何应用到小程序开发中
- What are the private addresses
- 那些考研后才知道的事
- Internal JSON-RPC error. {"code":-32000, "message": "execution reverted"} solve the error
猜你喜欢
随机推荐
Idea设置方法注释和类注释
Solution to the prompt of could not close zip file during phpword use
53. 最大子数组和:给你一个整数数组 nums ,请你找出一个具有最大和的连续子数组(子数组最少包含一个元素),返回其最大和。
Kafaka log collection
Zhubo Huangyu: it's really bad not to understand these gold frying skills
Address book (linked list implementation)
redis6事务和锁机制
kafaka 日志收集
Intranet penetration tool NetApp
What is information security? What is included? What is the difference with network security?
These 18 websites can make your page background cool
MySQL if else use case use
Convolutional Neural Networks简述
Rk3566 add LED
Network security HSRP protocol
How to deal with the Yellow Icon during the installation of wampserver
Wonderful express | Tencent cloud database June issue
How to divide a large 'tar' archive file into multiple files of a specific size
2022建筑焊工(建筑特殊工种)特种作业证考试题库及在线模拟考试
2022年机修钳工(高级)考试题模拟考试题库模拟考试平台操作









