<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic javascript how to remove an object from nested json array in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/javascript-how-to-remove-an-object-from-nested-json-array/m-p/11915678#M1963535</link>
    <description>&lt;P&gt;Hello,&lt;/P&gt;
  &lt;P&gt;Im facing a small issue to remove an object from nested json array which will get generated dynamically. Below is the json..&lt;/P&gt;
  &lt;P&gt;Actually my requirement is like, I have a JSON Tree, and user can add or delete multiple nodes..&lt;/P&gt;
  &lt;PRE&gt;&lt;CODE&gt;[{
	"mainTxt": "test",
	"subTxt": "SubTxt1",
	"nodes": [{
		"mainTxt": "test",
		"subTxt": "SubTxt2",
		"nodes": [{
			"mainTxt": "test",
			"subTxt": "test Operations",
			"nodes": [{
				"mainTxt": "test",
				"subTxt": "test Operations",
				"nodes": [{
					"mainTxt": "test",
					"subTxt": "test Operations"
				}]
			}]
		}]
	}, {
		"mainTxt": "test",
		"subTxt": "SubTxt3",
		"nodes": [{
			"mainTxt": "test",
			"subTxt": "test Operations",
			"nodes": [{
				"mainTxt": "test",
				"subTxt": "test Operations"
			}]
		}]
	}, {
		"mainTxt": "test",
		"subTxt": "india"
	}, {
		"mainTxt": "test",
		"subTxt": "SubTxt4"
	}, {
		"mainTxt": "test",
		"subTxt": "SubTxt5"
	}]
}]
&lt;/CODE&gt;&lt;/PRE&gt;
  &lt;P&gt;Here the below code blocks may get added or removed dynamically&lt;/P&gt;
  &lt;PRE&gt;&lt;CODE&gt;"nodes": [{
				"mainTxt": "test",
				"subTxt": "test Operations"
			}]
and
{
		"mainTxt": "test",
		"subTxt": "SubTxt5"
	}
&lt;/CODE&gt;&lt;/PRE&gt;
  &lt;P&gt;How can i remove above blocks which got added dynamically and after removing again i need to form the same JSON array.&lt;/P&gt;
  &lt;P&gt;I tried multiple ways in writing a loop by finding index of that particular object in array and tried to remove using &lt;STRONG&gt;splice() and delete()&lt;/STRONG&gt; method. But it didn't worked properly. &lt;/P&gt;
  &lt;P&gt;Can someone please help me if there is any simple fix?&lt;/P&gt;
  &lt;P&gt;Thank you in advance..&lt;/P&gt;</description>
    <pubDate>Tue, 07 May 2019 09:03:01 GMT</pubDate>
    <dc:creator>Former Member</dc:creator>
    <dc:date>2019-05-07T09:03:01Z</dc:date>
    <item>
      <title>javascript how to remove an object from nested json array</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/javascript-how-to-remove-an-object-from-nested-json-array/m-p/11915678#M1963535</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
  &lt;P&gt;Im facing a small issue to remove an object from nested json array which will get generated dynamically. Below is the json..&lt;/P&gt;
  &lt;P&gt;Actually my requirement is like, I have a JSON Tree, and user can add or delete multiple nodes..&lt;/P&gt;
  &lt;PRE&gt;&lt;CODE&gt;[{
	"mainTxt": "test",
	"subTxt": "SubTxt1",
	"nodes": [{
		"mainTxt": "test",
		"subTxt": "SubTxt2",
		"nodes": [{
			"mainTxt": "test",
			"subTxt": "test Operations",
			"nodes": [{
				"mainTxt": "test",
				"subTxt": "test Operations",
				"nodes": [{
					"mainTxt": "test",
					"subTxt": "test Operations"
				}]
			}]
		}]
	}, {
		"mainTxt": "test",
		"subTxt": "SubTxt3",
		"nodes": [{
			"mainTxt": "test",
			"subTxt": "test Operations",
			"nodes": [{
				"mainTxt": "test",
				"subTxt": "test Operations"
			}]
		}]
	}, {
		"mainTxt": "test",
		"subTxt": "india"
	}, {
		"mainTxt": "test",
		"subTxt": "SubTxt4"
	}, {
		"mainTxt": "test",
		"subTxt": "SubTxt5"
	}]
}]
&lt;/CODE&gt;&lt;/PRE&gt;
  &lt;P&gt;Here the below code blocks may get added or removed dynamically&lt;/P&gt;
  &lt;PRE&gt;&lt;CODE&gt;"nodes": [{
				"mainTxt": "test",
				"subTxt": "test Operations"
			}]
and
{
		"mainTxt": "test",
		"subTxt": "SubTxt5"
	}
&lt;/CODE&gt;&lt;/PRE&gt;
  &lt;P&gt;How can i remove above blocks which got added dynamically and after removing again i need to form the same JSON array.&lt;/P&gt;
  &lt;P&gt;I tried multiple ways in writing a loop by finding index of that particular object in array and tried to remove using &lt;STRONG&gt;splice() and delete()&lt;/STRONG&gt; method. But it didn't worked properly. &lt;/P&gt;
  &lt;P&gt;Can someone please help me if there is any simple fix?&lt;/P&gt;
  &lt;P&gt;Thank you in advance..&lt;/P&gt;</description>
      <pubDate>Tue, 07 May 2019 09:03:01 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/javascript-how-to-remove-an-object-from-nested-json-array/m-p/11915678#M1963535</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2019-05-07T09:03:01Z</dc:date>
    </item>
    <item>
      <title>Re: javascript how to remove an object from nested json array</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/javascript-how-to-remove-an-object-from-nested-json-array/m-p/11915679#M1963536</link>
      <description>&lt;P&gt;Fixed the issue with below Code..&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;removeTile:function(oEvt){
        this._deleteRecord(globalArray, selObject);
        _oModel.setData(oModelData);},
    _deleteRecord:function(items, record){if(items !== undefined){for(var i=0;i&amp;lt; items.length;i++){if(items[i]=== record){
                    items.splice(i,1);break;}else{
                    this._deleteRecord(items[i].nodes, record);}}}}&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 07 May 2019 15:22:15 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/javascript-how-to-remove-an-object-from-nested-json-array/m-p/11915679#M1963536</guid>
      <dc:creator>former_member610012</dc:creator>
      <dc:date>2019-05-07T15:22:15Z</dc:date>
    </item>
  </channel>
</rss>

