remove element from list seems easy but very tricky somehow. as code below

var x = "dacda cdac cd k foorar", a = x.split(" "), i=0;
for (i=0; i<a.length; i++) {
  if (a[i].length <4) {
    a.splice(i,1);
  }
}

But, it won’t work cause the length is changing. here is a solution

var x = "dacda cdac cd k foorar", a = x.split(" "), i=0;
var r = [];
for (i=0; i<a.length; i++) {	
  if (a[i].length >=4) {
    r.push(a[i]);
  }
} 
Advertisements