{"id":1090,"date":"2022-08-30T15:12:13","date_gmt":"2022-08-30T15:12:13","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2013\/11\/09\/refresh-json-after-delete-collection-of-common-programming-errors\/"},"modified":"2022-08-30T15:12:13","modified_gmt":"2022-08-30T15:12:13","slug":"refresh-json-after-delete-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2022\/08\/30\/refresh-json-after-delete-collection-of-common-programming-errors\/","title":{"rendered":"Refresh JSON after delete-Collection of common programming errors"},"content":{"rendered":"<p>I have got following JSON:<\/p>\n<pre><code> \"memberValidations\":\n       [\n           {\n               \"field\": \"PRIMARY_EMAIL\",\n               \"errorCode\": \"com.endeavour.data.validation.PRIMARY_EMAIL\",\n               \"createdDateTime\": null\n            },\n            {\n               \"field\": \"lastName\",\n               \"errorCode\": \"com.endeavour.data.validation.lastName\",\n               \"createdDateTime\": null\n             },\n       ]\n<\/code><\/pre>\n<p>After deleting an object <code>delete memberValidations[0];<\/code><\/p>\n<p>I&#8217;m expecting lastname from <code>memberValidations[0];<\/code> but getting undefined instead? Any idea how to fix this?<\/p>\n<ol>\n<li>\n<p>Using <code>delete<\/code> will remove the item from the array but it won&#8217;t resize it so effectively you still have an item at index <code>0<\/code> but it&#8217;s no longer assigned (<code>undefined<\/code>). From the docs<\/p>\n<blockquote>\n<p>When you delete an array element, the array length is not affected. This holds even if you delete the last element of the array.<\/p>\n<\/blockquote>\n<p>To remove the item completely you need to also resize the array e.g.<\/p>\n<pre><code>memberValidations.splice(0, 1)\n<\/code><\/pre>\n<\/li>\n<\/ol>\n<p id=\"rop\"><small>Originally posted 2013-11-09 23:22:37. <\/small><\/p>","protected":false},"excerpt":{"rendered":"<p>I have got following JSON: &#8220;memberValidations&#8221;: [ { &#8220;field&#8221;: &#8220;PRIMARY_EMAIL&#8221;, &#8220;errorCode&#8221;: &#8220;com.endeavour.data.validation.PRIMARY_EMAIL&#8221;, &#8220;createdDateTime&#8221;: null }, { &#8220;field&#8221;: &#8220;lastName&#8221;, &#8220;errorCode&#8221;: &#8220;com.endeavour.data.validation.lastName&#8221;, &#8220;createdDateTime&#8221;: null }, ] After deleting an object delete memberValidations[0]; I&#8217;m expecting lastname from memberValidations[0]; but getting undefined instead? Any idea how to fix this? Using delete will remove the item from the array but [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-1090","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/1090","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=1090"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/1090\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=1090"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=1090"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=1090"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}