There is an array like this:
var array = [
{SchoolId: 2 ,GraderId: 465 , SchoolGraderName: "Example1256"},
{SchoolId: 2 ,GraderId: 654,SchoolGraderName: "Example45"},
{SchoolId: 2 ,GraderId: 876,SchoolGraderName: "Example895"},
{SchoolId: 34 ,GraderId: 796,SchoolGraderName:"Example2156"},
{SchoolId: 45 ,GraderId: 356,SchoolGraderName:"Example315"},
{SchoolId: 45 ,GraderId: 457,SchoolGraderName:"Example56715"}
{SchoolId: 45 ,GraderId: 678,SchoolGraderName:"Example37675"}
{SchoolId: 45 ,GraderId: 465 ,SchoolGraderName:"Example97685615"}
]
I am trying to delete the whole objects Where the GraderId is some value (:
$(function() {
$("#schoolGraders").on("dblclick",
function() {
$.each(array,function(i,r){
if (r.GraderId == $(this).val()) {
r.removeItem;
}
});
});
the code above does not work.
Here is the HTML Code:
<select class="form-control" id="schoolGraders" style="width: 80%; height: 200px"
multiple></select>
I generate the options like this:
item = "";
$.ajax({
type: "GET",
url: "address" + $(this).val(),
contentType: "application/json",
dataType: "json"
}).done(function (res) {
var iteem = "";
$.each(res,
function (i, r) {
iteem += '<option value="' + r.id +
'">' + r.title + '</option>';
});
$("#graderSchools").html(iteem);
});
Is there any condition in JavaScript So I can remove objects WHERE the GraderId is some value ?