Hi, I provide training in SAP UI5. Also feel free to checkout my new web page https://saptechblog.com

Dynamically Creating a JSON Object Structure

In this tutorial i am going to explain how to create a JSON Structure dynamically. I had an requirement where i wanted to create an object dynamically to store the information on tab(Icon Tab Bar) and No of list that was dynamically created within the Tab to track them. So i had to create a dynamic structure to store that information tab wise.

Below is the Map Structure that i wanted to created dynamically as JavaScript object.




To create this map structure, i had dynamically inserted the key in the object with the name of Tab and Features.

To insert keys dynamically inside the object use the Notation []. This will check if there is already a key  in the object with the name passed. If there is already a key then it will pass the value to that key.Else it will introduce a new key with the name passed and assign values to it.


Code Snippet:


var aTabs = [ { tab: " pre >< console.log(map);          }); i++;                 map[row.tab][row.featureName]="i;" } map[row.tab]="{};" undefined){ if(map[row.tab]="=" aTabs.forEach(function(row){ i="0;" var map="{};" ?feature1?}] featureName: ?tab2?, tab:  {     ?feature3?}, ?tab1?,                       ?feature2?}, {      ?feature1?}, tab1?,>

About Arun


  1. // Sample array
    var aTabs = [ { tab: "tab1", featureName: "feature1"},
    { tab: "tab1", featureName: "feature2"},
    { tab: "tab1", featureName: "feature3"},
    { tab: "tab2", featureName: "feature1"}]

    var map = {};
    var i = 0;
    if(map[row.tab] == undefined){
    map[row.tab] = {};
    map[row.tab][row.featureName] = i;




Powered by Blogger.