“Hapus array dari array javascript” Kode Jawaban

JavaScript Hapus elemen dari array

var colors = ["red","blue","car","green"];
var carIndex = colors.indexOf("car");//get  "car" index
//remove car from the colors array
colors.splice(carIndex, 1); // colors = ["red","blue","green"]
Grepper

cara menghapus elemen dari array di javascript

var colors = ["red","blue","car","green"];
var carIndex = colors.indexOf("car");//get  "car" index
//remove car from the colors array
colors.splice(carIndex, 1); // colors = ["red","blue","green"]
Anxious Anaconda

Hapus elemen dari array di JS

var myArray = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"];

//removing element using splice method -- 
//arr.splice(index of the item to be removed, number of elements to be removed)
//Here lets remove Sunday -- index 0 and Monday -- index 1
  myArray.splice(0,2)

//using filter method
let itemToBeRemoved = ["Sunday", "Monday"]
var filteredArray = myArray.filter(item => !itemToBeRemoved.includes(item))
JavascriptNinja

Hapus Elemen Array JavaScript

let value = 3

let arr = [1, 2, 3, 4, 5, 3]

arr = arr.filter(item => item !== value)

console.log(arr)
// [ 1, 2, 4, 5 ]
Proud Pollan

Hapus Elemen Array JavaScript

let forDeletion = [2, 3, 5]

let arr = [1, 2, 3, 4, 5, 3]

arr = arr.filter(item => !forDeletion.includes(item))
// !!! Read below about array.includes(...) support !!!

console.log(arr)
// [ 1, 4 ]
Proud Pollan

Hapus array dari array javascript

myArray = myArray.filter( ( el ) => !toRemove.includes( el ) );
Lively Ladybird

Jawaban yang mirip dengan “Hapus array dari array javascript”

Pertanyaan yang mirip dengan “Hapus array dari array javascript”

Lebih banyak jawaban terkait untuk “Hapus array dari array javascript” di JavaScript

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya