# .splice() method -is skipping a index - delete & .filter() is not working perfectly - any other method to do this?

here is a commented code, i am puting clean code under it second time

``````// example of decimal number [1.2,2.22,3.54,5.21,1.27,6.30,0.30,7.77.. like that]

let decimalNumber = [0,1,2,1.2,2.22,5,7,8,3.54,5.21,1.27,6.30,0.30,7.77];

for(let x=1; x<3; x++){   ////  when i run two time its working perfectly. //it's mean its check second time for nondecimal and remove it
for(let key in decimalNumber){
let storeAllvalue = decimalNumber[key];
let checkDecimal = decimalNumber[key].toFixed(0);
//console.log(checkDecimal, "=", storeAllvalue); //print this to understand how it work
if(storeAllvalue == checkDecimal){ // if i use strickcheck here, and if any string in array -throw ana error , because .tofixed()is number method
//console.log(storeAllvalue, "=", checkDecimal);
let findIndexfornonDecimal = decimalNumber.indexOf(storeAllvalue);
decimalNumber.splice(findIndexfornonDecimal, 1); // not working perfectly. //it's skiping next  index why
//console.log(findIndexfornonDecimal);

// delete decimalNumber[findIndexfornonDecimal]; // remove right but still index is not rearranged.
}
}
};

console.log(decimalNumber);

``````

clean code

``````//try it to see index skipping

let decimalNumber = [ 0, 1, 2, 1.2, 2.22, 5, 7, 8, 3.54, 5.21, 1.27, 6.3, 0.3, 7.77,];

for (let key in decimalNumber) {
let a = decimalNumber[key];
let b = decimalNumber[key].toFixed(0);

if (a == b) {
let c = decimalNumber.indexOf(a);
decimalNumber.splice(c, 1); //try it to see index skipping
}
}

console.log(decimalNumber);
``````

.filter() Method

``````
// example of decimal number [1.2,2.22,3.54,5.21,1.27,6.30,0.30,7.77.. like that]

//.filter() -method -not fine
let decimalNumbers = [0,1,2,1.2,2.22,5,7,8,3.54,5.21,1.27,6.30,0.30,7.77];

let result  = decimalNumbers.filter(
function (value){
let fixed = value.toFixed(0);
if (value !== fixed){  // working fine in ==
return  true    // it's returning all numbers as it as
}
}
);
console.log(result);
``````

working code for me

``````let decimalNumber = [ 0, 1, 2, 1.2, 2.22, 5, 7, 8, 3.54, 5.21, 1.27, 6.3, 0.3, 7.77,];

for (let x = 1; x < 3; x++) {
for (let key in decimalNumber) {
let a = decimalNumber[key];
let b = decimalNumber[key].toFixed(0);
if (a == b) {
let c = decimalNumber.indexOf(a);
decimalNumber.splice(c, 1);
}
}
}

console.log(decimalNumber);
``````