Deleting objects from JSON
by VENKATA VINAY BYSANI
HTML
<ul id="result"></ul>
<button id="btn">Load Data</button>
CSS
body{
font-family: "Monaco", "Andale Mono", "Lucida Console", "Bitstream Vera Sans Mono", "Courier New", Courier, monospace;
font-size: .85em;
}
JavaScript
$("#btn").click(function () {
$("#result").append('<li>.....Before Deletion.....</li><li></li>');
$.each(uiPropsJSON, function (key, value) {
$("#result").append('<li>' + key + ' :: ' + value[value.length - 1].OtherData + '</li>');
delete value[value.length - 1];
});
$("#result").append('<li></li><li>.....After Deletion.....</li><li></li>');
$.each(uiPropsJSON, function (key, value) {
var currentVal = value[value.length - 1] != null ? value[value.length - 1] : "<font color='red'>Deleted</font>";
$("#result").append('<li>' + key + ' :: ' + currentVal + '</li>');
});
});
var uiPropsJSON = {
"OSName": [{
"PL": "Name",
"PT": "Is like",
"PSC": "Name Criteria",
"id": "nameId"
}, {
"PL": "User ID",
"PT": "In",
"PSC": "User Criteria",
"id": "userID"
}, {
"PL": "Emp ID",
"PT": "In",
"PSC": "Emp Criteria",
"id": "empID"
}, {
"OtherData": "Other Data As Required"
}],
"OSName1": [{
"PL": "Name11",
"PT": "Is like",
"PSC": "",
"id": "nameId"
}, {
"PL": "User ID11",
"PT": "In",
"PSC": "",
"id": "userID"
}, {
"PL": "Emp ID11",
"PT": "In",
"PSC": "",
"id": "empID"
}, {
"OtherData": "Other Data As Required1"
}]
};