How to log array or object without some elements


I have the object

"Name": "dfdfdfd",

How to log object without "geoData" or without "geoData" and "type2"?

I want to have that kind of result without changing main object.

result - {"ID":2,"Name": "dfdfdfd","type":"Point","type2":"Point"}

>Solution :

One way to achieve this is to use the delete operator to remove the unwanted properties from the object. Here’s an example:

const object = {"ID":2, "Name": "dfdfdfd", "type":"Point", "type2":"Point", "geoData":{"coordinates":[37.900526,55.414307],"type":"Point"}};

delete object.geoData;
delete object.type2;


This code will delete the geoData and type2 properties from the object and log the resulting object to the console. The output will be:

{"ID":2,"Name": "dfdfdfd","type":"Point"}

Note that this method modifies the original object. If you want to keep the original object intact, you can create a copy of it and modify the copy instead.

Leave a ReplyCancel reply