Remove multiple elements from array in Javascript/jQuery

后端 未结 22 2347
梦毁少年i
梦毁少年i 2021-01-29 19:42

I have two arrays. The first array contains some values while the second array contains indices of the values which should be removed from the first array. For example:

<
22条回答
  •  自闭症患者
    2021-01-29 20:29

    You could construct a Set from the array and then create an array from the set.

    const array = [1, 1, 2, 3, 5, 5, 1];
    const uniqueArray = [...new Set(array)];
    console.log(uniqueArray); // Result: [1, 2, 3, 5]
    

提交回复
热议问题