I may be wrong on what I think .splice() is meant to do, but I thought it removed one element of an array. All I want to do here is remove “pears”, but it doesn’t work:
var my_array = ["apples","pears","bananas","oranges"];
my_array.splice($.inArray("pears",my_array));
$.each(my_array, function(k,v) {
document.write(v+"<br>");
});
You’re missing two arguments:
$.inArraywants the second argument to be the subject arrayspliceaccepts a second argument to specify the number of elements to be deletedThe code becomes:
Live example