Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I remove null from JSON object with AngularJS?

I'm trying to remove an object from Json Object it works..but it replace it with null..i dont know why, how can i remove the null value from the json..heres the function :

company.deleteExternalLinkFromGrid = function (row, matricule) {
        // console.log('Inside of deleteModal, code = ' + code);
        //$scope.sitting= {};
       console.log(matricule);
        //console.log(JSON.stringify(linkJsonObj));
        delete linkJsonObj[matricule];

        console.log(JSON.stringify(linkJsonObj));
    };

heres the object:

[{"name":"xxx","link":"www.ddd.com","id":0,"$$hashKey":"uiGrid-001Z"},null,null]


1 Answers

You can use filter(), x will be without null's.

function test()
{
    var x =[{"name":"xxx","link":"www.ddd.com","id":0,"$$hashKey":"uiGrid-001Z"},null,null].filter(isNotNull);
    alert(JSON.stringify(x));

}

function isNotNull(value) {
  return value != null;
}

fiddle

like image 143
M. Wiśnicki Avatar answered Jul 13 '26 21:07

M. Wiśnicki



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!