온라인 시간과 오프라인 시간을 비교할 시간이 필요합니다. 온라인 시간보다 오프라인 시간이 더 많은 경우 - 이번에는 삭제해야합니다. 사용자에게 타임 라인이없는 경우 -이 사용자를 삭제해야합니다. 시간을 통과 할 때와 smažuj은 다음과 같습니다 :이 데이터 구조에서 js 배열의 데이터를 삭제하는 방법은 무엇입니까?
나는이 문제가 "정의되지 않은"값이 남아있다 - [정의되지 않은, 정의되지 않은] 다음이 조건이 만족 될 수없는 -
if (user.connectionTimes.length === 0) {
delete users[id];
}
어떻게해야하나요 이 문제를 해결 하시겠습니까?
var users = [];
users[0] = {
userId: 1,
connectionTimes:
[
{onlineTime:30, offlineTime:70},
{onlineTime:50, offlineTime:75}
]
};
users[1] = {
userId: 2,
connectionTimes:
[
{onlineTime:80, offlineTime:70}
]
};
users[2] = {
userId: 3,
connectionTimes: []
};
for(var i=0; i<users.length; i++) {
for(var j=0; j<users[i].connectionTimes.length; j++) {
if(users[i].connectionTimes[j].onlineTime < users[i].connectionTimes[j].offlineTime) {
delete users[i].connectionTimes[j];
//EDIT - this work - users[i].connectionTimes.splice(j, 1);
//j--;
}
}
if(users[i].connectionTimes.length == 0) {
delete users[i];
//EDIT - this work - users.splice(i, 1);
//i--;
}
}
console.log(users);
가 어떻게이 상태에서이 기능을 "스플 라이스"를 사용 하는가를? 'if (connectionTime.onlineTime
Jenan
'user.connectionTimes.splice (i, 1)'? – SLaks