JavaScript 中数组交集最简单的代码是什么?
javascriptobject oriented programmingfront end technology
对于数组交集,您可以尝试在 JavaScript 中运行以下代码 −
示例
<html> <body> <script> let Intersection = function(x, y) { x = new Set(x), y = new Set(y); return [...x].filter(k => y.has(k)); }; document.write(intersection([5,7,4,8], [3,9,8,4,3])); </script> </body> </html>