var set = new Set([1, 2, 3]); set.forEach(function (element, type ,self) { console.log(element); console.log(type); console.log(self); })
结果是: 1 1 Set {1, 2, 3} 2 2 Set {1, 2, 3} 3 3 Set {1, 2, 3}
如果是两个参数:
var set = new Set([1, 2, 3]); set.forEach(function (element ,self) { console.log(element); console.log(self); })
结果是: 1 1 2 2 3 3
说明Set的forEach也应该是3个参数,并且第三个参数是其本身
你说得对,set前两个参数是完全一样的:
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/forEach
Sign in to make a reply
现在_12020
结果是: 1 1 Set {1, 2, 3} 2 2 Set {1, 2, 3} 3 3 Set {1, 2, 3}
如果是两个参数:
结果是: 1 1 2 2 3 3
说明Set的forEach也应该是3个参数,并且第三个参数是其本身