Remove item from JSON object Array using JavaScript and jQuery

Last Reply 4 months ago By dharmendr

Posted 4 months ago

Hello All,

I have model collection in JQUERY thiz.tprListSearchesAndViews.searchParameters[0].parameters.

This has 16 parameters list, as shown in the Image 1, I need to remove 2 items in the the parameters collection.

Could you please help me, how I can do this. I am not getting any idea how I can approach on this using Jquery.

Image1 :

https://i.stack.imgur.com/pd58H.jpg

Image2 :

https://i.stack.imgur.com/5p4eU.png

Posted 4 months ago Modified on 4 months ago

Hi bhadriau,

Use jQuery splice Method.

Refer below example.

HTML

<script type="text/javascript">
    function RemoveItems(index) {
        var customers = [{ CustomerId: 1, Name: "John Hammond", Country: "United States" },
                        { CustomerId: 2, Name: "Mudassar Khan", Country: "India" },
                        { CustomerId: 3, Name: "Suzanne Mathews", Country: "France" },
                        { CustomerId: 4, Name: "Robert Schidner", Country: "Russia"}];
        // Remove item from specified index.
        customers.splice(index, 1);
    }
</script>
<input type="button" value="Submit" onclick="RemoveItems(1);" />

 

Output