Remove item in array javascript es6

array,tipjs

Những bạn nào mà đã sử dụng ES6 một thời gian rồi thì có thể sử dụng method array.filter() 

# remove a item in array

const items = [1, 2, 3, 4, 5]
const valueToRemove = 4
const filteredItems = items.filter(item => item !== valueToRemove)
/*
  Output:
  [1, 2, 3, 5]
*/

# sử dụng array.filter() để remove multiple item in array javascript

const items = [1, 2, 3, 4, 5]
const valuesToRemove = [3, 4]
const filteredItems = items.filter(item => !valuesToRemove.includes(item))
console.log(filteredItems)
/*
  Output:
  [1, 2, 5]
*/

Có thể bạn đã miss một số snippets code

Đếm số phần tử trong mảng JavaScript

Đếm số lần xuất hiện của các phần tử trong mảng JavaScript

flatMap()

Use flatMap() creates a new array with sub-array elements flattened by specified depth.

Rest Operator for Objects

Now we can use rest on the properties of an Object. It allows us to explicitly extract certain named variables, and assign any uncalled variables into a catchall Object.

Sự khác biệt giữa substr và substring

Sự khác biệt giữa substr() và substring() chức năng trong JS là gì?

Copy a string to the clipboard

Copy a string to the clipboard. Only works as a result of user action (i.e. inside a click event listener).