Click here to Skip to main content
15,891,513 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am working on MVC 5 project.

What I have tried:

Here I trying to remove json object.

JavaScript
var hidJson = JSON.parse(hidvalue);      
        $.each(hidJson.Form5.Projects, function (i, obj) {
            if (obj != null) {
                if (obj.idPartnerProject == idPartnerProject) {

                    delete hidJson.Form5.Projects[i];              
                }
            }
        });


But after delete the item deleted but the length of array is not resetting. How can I do this ? This causing 'null' caring array element issue. please look upon below image.
[^]

Please help me...
Posted
Updated 13-May-17 2:44am
v2
Comments
[no name] 13-May-17 8:56am    
Because that's not how arrays work.
Member 12955507 13-May-17 9:02am    
How can I delete array element ?
[no name] 13-May-17 9:26am    
You already are. To do what you think needs to happen, you copy the not null elements to another array. Or learn how to check element for being null.

1 solution

I have changed the code like this,

JavaScript
hidJson.Form5.Projects.splice(i, 1);


and removed this code:
JavaScript
delete hidJson.Form5.Projects[i];  


Now the array refreshed !!!
 
Share this answer
 
v2
Comments
PIEBALDconsult 25-Jun-17 23:46pm    
Please do not answer your own question. Simply add more information via "Improve question".

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900