여기에서 json 객체에서 특정 Array [2]를 삭제하려고합니다. 하지만 콘솔에서 볼 수 있습니다 - 배열 값을 삭제 된 있지만 삭제 된 후 jquery $.each
사용하여 체크했을 때 idx 남아 있습니다. 그럼, 올바른 방법으로 전체 배열 객체를 삭제하는 방법은?json 객체에서 json Array 제거
var obj = {
equipments:'first',
\t messages:['msg1','msg2','msg3'], \t
}
console.log(obj);
$.each(obj.messages, function (idx, obj) {
alert("before deleted index value" +idx);
});
obj1 = obj;
if(obj1["equipments"] == 'first') {
delete obj1.messages[2];
}
console.log(obj1);
$.each(obj1.messages, function (idx, obj1) {
alert("after deleted but index remains same" +idx);
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
여기와 같습니다 - http://stackoverflow.com/questions/500606/javascript-array-delete-elements –