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

Kiểm tra phần tử trùng trong mảng JavaScript

Kiểm tra phần tử trùng trong mảng JavaScript.

So sánh hai array trong javascript

Làm thế nào để đánh giá xem hai mảng có bằng nhau không? Có hai cách đó là sử dụng JSON.stringify() hoặc toString()

Object.keys và Object.getOwnPropertyNames

Object.keys và Object.getOwnPropertyNames

Remove array of objects from another array of objects

Remove array of objects from another array of objects

How to reverse an Array?

Reversing an array in JS is really simple with the standard array method. Like below