Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to log array or object without some elements

I have the object

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

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

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

console.log(object.instead("geoData")); 
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;

console.log(object);

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.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading