{"id":4266,"date":"2016-05-31T01:26:54","date_gmt":"2016-05-31T01:26:54","guid":{"rendered":"http:\/\/www.garysieling.com\/blog\/?p=4266"},"modified":"2016-05-31T01:26:54","modified_gmt":"2016-05-31T01:26:54","slug":"lodash-clone-without","status":"publish","type":"post","link":"https:\/\/www.garysieling.com\/blog\/lodash-clone-without\/","title":{"rendered":"Lodash: clone without"},"content":{"rendered":"<p>Sometimes it&#8217;s useful to be able to clone an object in Javascript, but remove some items.<\/p>\n<p>For instance, if you look at the AST for a Javascript file, the nodes look like this:<\/p>\n<pre lang=\"Javascript\">\n{\n  \"type\": \"BinaryExpression\",\n  \"operator\": \"+\",\n  \"left\": {\n    \"type\": \"BinaryExpression\",\n    \"operator\": \"+\",\n    \"left\": {\n      \"type\": \"Literal\",\n      \"value\": \"Cannot find module '\",\n      \"raw\": \"\\\"Cannot find module '\\\"\"\n    },\n    \"right\": {\n      \"type\": \"Identifier\",\n      \"name\": \"o\"\n    }\n  },\n  \"right\": {\n    \"type\": \"Literal\",\n    \"value\": \"'\",\n    \"raw\": \"\\\"'\\\"\"\n  }\n}\n<\/pre>\n<p>If you were trying to track these as you traverse the tree (e.g. using Estraverse) you would want just the root (without the &#8220;left&#8221; and &#8220;right&#8221; bits).<\/p>\n<p>Fortunately, there is an easy way to do just that:<\/p>\n<pre lang=\"javascript\">\ntree.push(\n  _.omit(\n    node, \n    [\"left\", \"right\"]\n  )\n);\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>An easy way to eliminate bits of Javascript objects<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"om_disable_all_campaigns":false,"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[4],"tags":[302,343],"aioseo_notices":[],"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/posts\/4266"}],"collection":[{"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/comments?post=4266"}],"version-history":[{"count":0,"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/posts\/4266\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/media?parent=4266"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/categories?post=4266"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/tags?post=4266"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}