I created a array with objects in javascript. that's what i got:
object[
{position:1, value:23},
{position:34, value:22 },
{position:2, value:10},
{position:35,value:9}.....
]
So i want to create a for loop, that deletes those objects who's destination (e.g. destination =(object1.position - object2.position) *-1) is lower than 18 to the previous objects.
for example: object[2].position is 1 position apart from object[0].position so object[2] is not needed anymore. The same for object[3] ... 35 - 34 = 1 / 1<18 / object[3] not needed.
that's what i wrote:
myfullarray = [
{pos:1,value:23},
{pos:34,value:22},
{pos:2,value:10},
(...)
]
myarray = [];
myarray[0] = {
pos:myfullarray[0].pos,
value:myfullarray[0].value
}
for(i=1;i<myarray.length;i++){
for(d=i;d>0;d--){
mydest = myfullarray[i].pos-myfullarray[d].pos;
if(mydest<0){
mydest *= -1
}
if(mydest<18){
}else{
myarray[myarray.length + 1] = {
value:myfullarray[i].value,
pos:myfullarray[i].pos
};
}
}
}
Can someone help me with this problem ?
splice()
,pop()
, orshift()
... so, you're certainly not removing any items. – canon Sep 24 '13 at 20:47code
(myarraylength) – mynameisgod Sep 24 '13 at 20:49