0

I want to convert string into array using split when i have this string which i want to convert it to array. Here is my code :

var str = "Hello  I am     Here";
var separator = str.split(" ");
console.log(separator); // returns ['Hello', '', 'I', 'am', '', '', '', '', 'Here']
for(var i in separator){
    if(separator[i] == ""){
        separator.splice(i,1);
    }
}
console.log(separator); // returns ['Hello', 'I', 'am', '', '', 'Here']

but when i'm using split and deleting some null strings some of them arent deleted. why?

0 Answers0