无法通过所有阵列了解如何循环并将其推入一个避免重复,这样我就可以有这样的结果:合并数目不详阵列没有重复
['All', 'Images', 'Video']
到目前为止,我现在有下面,但并不预期:
let filterize = function(el, config){
\t let target = document.getElementById(el);
\t let arrayCommon;
\t for(let value in config) { \t \t
\t \t arrayCommon = [...new Set([...config[value].filter])];
\t }
\t
\t console.log(arrayCommon)
\t
\t
}
var filterize_init = new filterize('Filtered', {
\t element_1: {
\t \t filter: ['All', 'Image']
\t },
\t element_2: {
\t \t filter: ['All', 'Video']
\t }
})
<div class="wrapper">
\t <div id="Filtered" class="filter-content">
\t \t
\t </div>
</div>
谁能帮助?
的可能的复制[如何合并在Javascript两个数组并删除重复的项目](http://stackoverflow.com/questions/1584370/how-to-merge-two-arrays-in-javascript-and-de-duplicate-items) – George
是的,我读过那个话题......但是已知数量的数组。现在这就是我的问题。不能理解如何遍历所有(未知数)数组,可以由用户添加:它可能是两个或更多。 – NeedHate
循环中的行覆盖之前的arrayCommon,而不是添加到它。 – nnnnnn