remove element from array in js
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"]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))
Also in JavaScript:
- set attribute javascript background image
- Iterate with JavaScript While Loops
- export default arrow function
- starting with react router dom
- how write a email validation regex
- event.target javascript
- npm simple zip file creator
- How to pass a map from controller to javascript function in VF page
- parseint function javascript
- react return action in a function
- using post from any button
- js add src to img
- ignore node_modules
- jquery append to table
- jquery clear chozen
- javascript change image src
- how to make a vertical array js
- anchor click event angular refresh page
- delete element html javascript
- javascript ternary operator
- js arrow function
- convert table to excel reactjs
- javascript note
- in javascript check is is an array or not