remove a particular element from 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"]
remove a particular element from 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"]
javascript empty array
arr = []; // set array=[]
//function
const empty = arr => arr.length = 0;
//example
var arr= [1,2,3,4,5];
empty(arr) // arr=[]
js delete all array items
A.splice(0,A.length)
javascript clear array
let aray = [1,2,3,4,5,6,7,8,9,10];
//as with most coding there are several ways you can do anything
//see whichever works best for your scenario
//set the array to equal a blank array
array = [];
//set the array's length to 0
array.length = 0;
//using splice, starts at index 0 & removes everything up to and including that last index
array.splice(0, array.length);
//map or loop through and shift() or pop();
//goes through the array one at a time and removes the last item each time
array.map( () => array.pop());
//goes through the array one at a time and removes the first item each time
array.map( () => array.shift());
js delete all array items
A = [];
js delete all from array
var list = [1, 2, 3, 4];
function empty() {
//empty your array
list.length = 0;
}
empty();
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us