-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDelArray.js
More file actions
36 lines (35 loc) · 1 KB
/
DelArray.js
File metadata and controls
36 lines (35 loc) · 1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
/*
array :- the array from which the value you want to del;
value :- the value you want to delete;
times :- how much the same value you want to delete;
*/
function delArray(array,value,times){
try{
if((array==null)&&(value==null)){
throw new Error('This Function Expect\'s Two Parameter');
}else if(!(array instanceof Array)){
throw new Error("First Argument Should Be An Array");
}else if(typeof(value)=='object'){
throw new Error("Second Argument Should Be A String Or A Number");
}else{
if(times!=null){
var num=Number(times);
if(isNaN(num)||typeof(times)=='object'){
throw new Error('third argument should be a number');
}
for(var i=0;i<times;i++){
array.splice(array.indexOf(value),1);
};
}else{
array.forEach(function(val,ind){
if(val==value){
array.splice(array.indexOf(value),1);
}
});
}
return array;
}
}catch(error){
console.log("%c"+error.message,'color:red;font-size:16px;font-family:arial');
}
}