Related
Given an object with an array of pokemons, i need to extract only the ones that start with a and put them into an array. And the same with the ones that start with b.
These arrays will be inside an onject. something like this. how would you do it? (using Javascript)
I tried many ways with for each and split methods.
*//const namePokemons {
// “a”: []
// “b”: []
//}
const pokemonMock = {
"count": 1118,
"next": "https://pokeapi.co/api/v2/pokemon?offset=300&limit=100",
"previous": "https://pokeapi.co/api/v2/pokemon?offset=100&limit=100",
"results": [
{
"name": "unown",
"url": "https://pokeapi.co/api/v2/pokemon/201/"
},
{
"name": "wobbuffet",
"url": "https://pokeapi.co/api/v2/pokemon/202/"
},
{
"name": "girafarig",
"url": "https://pokeapi.co/api/v2/pokemon/203/"
},
{
"name": "pineco",
"url": "https://pokeapi.co/api/v2/pokemon/204/"
},
{
"name": "forretress",
"url": "https://pokeapi.co/api/v2/pokemon/205/"
},
{
"name": "dunsparce",
"url": "https://pokeapi.co/api/v2/pokemon/206/"
},
{
"name": "gligar",
"url": "https://pokeapi.co/api/v2/pokemon/207/"
},
{
"name": "steelix",
"url": "https://pokeapi.co/api/v2/pokemon/208/"
},
{
"name": "snubbull",
"url": "https://pokeapi.co/api/v2/pokemon/209/"
},
{
"name": "granbull",
"url": "https://pokeapi.co/api/v2/pokemon/210/"
},
{
"name": "qwilfish",
"url": "https://pokeapi.co/api/v2/pokemon/211/"
},
{
"name": "scizor",
"url": "https://pokeapi.co/api/v2/pokemon/212/"
},
{
"name": "shuckle",
"url": "https://pokeapi.co/api/v2/pokemon/213/"
},
{
"name": "heracross",
"url": "https://pokeapi.co/api/v2/pokemon/214/"
},
{
"name": "sneasel",
"url": "https://pokeapi.co/api/v2/pokemon/215/"
},
{
"name": "teddiursa",
"url": "https://pokeapi.co/api/v2/pokemon/216/"
},
{
"name": "ursaring",
"url": "https://pokeapi.co/api/v2/pokemon/217/"
},
{
"name": "slugma",
"url": "https://pokeapi.co/api/v2/pokemon/218/"
},
{
"name": "magcargo",
"url": "https://pokeapi.co/api/v2/pokemon/219/"
},
{
"name": "swinub",
"url": "https://pokeapi.co/api/v2/pokemon/220/"
},
{
"name": "piloswine",
"url": "https://pokeapi.co/api/v2/pokemon/221/"
},
{
"name": "corsola",
"url": "https://pokeapi.co/api/v2/pokemon/222/"
},
{
"name": "remoraid",
"url": "https://pokeapi.co/api/v2/pokemon/223/"
},
{
"name": "octillery",
"url": "https://pokeapi.co/api/v2/pokemon/224/"
},
{
"name": "delibird",
"url": "https://pokeapi.co/api/v2/pokemon/225/"
},
{
"name": "mantine",
"url": "https://pokeapi.co/api/v2/pokemon/226/"
},
{
"name": "skarmory",
"url": "https://pokeapi.co/api/v2/pokemon/227/"
},
{
"name": "houndour",
"url": "https://pokeapi.co/api/v2/pokemon/228/"
},
{
"name": "houndoom",
"url": "https://pokeapi.co/api/v2/pokemon/229/"
},
{
"name": "kingdra",
"url": "https://pokeapi.co/api/v2/pokemon/230/"
},
{
"name": "phanpy",
"url": "https://pokeapi.co/api/v2/pokemon/231/"
},
{
"name": "donphan",
"url": "https://pokeapi.co/api/v2/pokemon/232/"
},
{
"name": "porygon2",
"url": "https://pokeapi.co/api/v2/pokemon/233/"
},
{
"name": "stantler",
"url": "https://pokeapi.co/api/v2/pokemon/234/"
},
{
"name": "smeargle",
"url": "https://pokeapi.co/api/v2/pokemon/235/"
},
{
"name": "tyrogue",
"url": "https://pokeapi.co/api/v2/pokemon/236/"
},
{
"name": "hitmontop",
"url": "https://pokeapi.co/api/v2/pokemon/237/"
},
{
"name": "smoochum",
"url": "https://pokeapi.co/api/v2/pokemon/238/"
},
{
"name": "elekid",
"url": "https://pokeapi.co/api/v2/pokemon/239/"
},
{
"name": "magby",
"url": "https://pokeapi.co/api/v2/pokemon/240/"
},
{
"name": "miltank",
"url": "https://pokeapi.co/api/v2/pokemon/241/"
},
{
"name": "blissey",
"url": "https://pokeapi.co/api/v2/pokemon/242/"
},
{
"name": "raikou",
"url": "https://pokeapi.co/api/v2/pokemon/243/"
},
{
"name": "entei",
"url": "https://pokeapi.co/api/v2/pokemon/244/"
},
{
"name": "suicune",
"url": "https://pokeapi.co/api/v2/pokemon/245/"
},
{
"name": "larvitar",
"url": "https://pokeapi.co/api/v2/pokemon/246/"
},
{
"name": "pupitar",
"url": "https://pokeapi.co/api/v2/pokemon/247/"
},
{
"name": "tyranitar",
"url": "https://pokeapi.co/api/v2/pokemon/248/"
},
{
"name": "lugia",
"url": "https://pokeapi.co/api/v2/pokemon/249/"
},
{
"name": "ho-oh",
"url": "https://pokeapi.co/api/v2/pokemon/250/"
},
{
"name": "celebi",
"url": "https://pokeapi.co/api/v2/pokemon/251/"
},
{
"name": "treecko",
"url": "https://pokeapi.co/api/v2/pokemon/252/"
},
{
"name": "grovyle",
"url": "https://pokeapi.co/api/v2/pokemon/253/"
},
{
"name": "sceptile",
"url": "https://pokeapi.co/api/v2/pokemon/254/"
},
{
"name": "torchic",
"url": "https://pokeapi.co/api/v2/pokemon/255/"
},
{
"name": "combusken",
"url": "https://pokeapi.co/api/v2/pokemon/256/"
},
{
"name": "blaziken",
"url": "https://pokeapi.co/api/v2/pokemon/257/"
},
{
"name": "mudkip",
"url": "https://pokeapi.co/api/v2/pokemon/258/"
},
{
"name": "marshtomp",
"url": "https://pokeapi.co/api/v2/pokemon/259/"
},
{
"name": "swampert",
"url": "https://pokeapi.co/api/v2/pokemon/260/"
},
{
"name": "poochyena",
"url": "https://pokeapi.co/api/v2/pokemon/261/"
},
{
"name": "mightyena",
"url": "https://pokeapi.co/api/v2/pokemon/262/"
},
{
"name": "zigzagoon",
"url": "https://pokeapi.co/api/v2/pokemon/263/"
},
{
"name": "linoone",
"url": "https://pokeapi.co/api/v2/pokemon/264/"
},
{
"name": "wurmple",
"url": "https://pokeapi.co/api/v2/pokemon/265/"
},
{
"name": "silcoon",
"url": "https://pokeapi.co/api/v2/pokemon/266/"
},
{
"name": "beautifly",
"url": "https://pokeapi.co/api/v2/pokemon/267/"
},
{
"name": "cascoon",
"url": "https://pokeapi.co/api/v2/pokemon/268/"
},
{
"name": "dustox",
"url": "https://pokeapi.co/api/v2/pokemon/269/"
},
{
"name": "lotad",
"url": "https://pokeapi.co/api/v2/pokemon/270/"
},
{
"name": "lombre",
"url": "https://pokeapi.co/api/v2/pokemon/271/"
},
{
"name": "ludicolo",
"url": "https://pokeapi.co/api/v2/pokemon/272/"
},
{
"name": "seedot",
"url": "https://pokeapi.co/api/v2/pokemon/273/"
},
{
"name": "nuzleaf",
"url": "https://pokeapi.co/api/v2/pokemon/274/"
},
{
"name": "shiftry",
"url": "https://pokeapi.co/api/v2/pokemon/275/"
},
{
"name": "taillow",
"url": "https://pokeapi.co/api/v2/pokemon/276/"
},
{
"name": "swellow",
"url": "https://pokeapi.co/api/v2/pokemon/277/"
},
{
"name": "wingull",
"url": "https://pokeapi.co/api/v2/pokemon/278/"
},
{
"name": "pelipper",
"url": "https://pokeapi.co/api/v2/pokemon/279/"
},
{
"name": "ralts",
"url": "https://pokeapi.co/api/v2/pokemon/280/"
},
{
"name": "kirlia",
"url": "https://pokeapi.co/api/v2/pokemon/281/"
},
{
"name": "gardevoir",
"url": "https://pokeapi.co/api/v2/pokemon/282/"
},
{
"name": "surskit",
"url": "https://pokeapi.co/api/v2/pokemon/283/"
},
{
"name": "masquerain",
"url": "https://pokeapi.co/api/v2/pokemon/284/"
},
{
"name": "shroomish",
"url": "https://pokeapi.co/api/v2/pokemon/285/"
},
{
"name": "breloom",
"url": "https://pokeapi.co/api/v2/pokemon/286/"
},
{
"name": "slakoth",
"url": "https://pokeapi.co/api/v2/pokemon/287/"
},
{
"name": "vigoroth",
"url": "https://pokeapi.co/api/v2/pokemon/288/"
},
{
"name": "slaking",
"url": "https://pokeapi.co/api/v2/pokemon/289/"
},
{
"name": "nincada",
"url": "https://pokeapi.co/api/v2/pokemon/290/"
},
{
"name": "ninjask",
"url": "https://pokeapi.co/api/v2/pokemon/291/"
},
{
"name": "shedinja",
"url": "https://pokeapi.co/api/v2/pokemon/292/"
},
{
"name": "whismur",
"url": "https://pokeapi.co/api/v2/pokemon/293/"
},
{
"name": "loudred",
"url": "https://pokeapi.co/api/v2/pokemon/294/"
},
{
"name": "exploud",
"url": "https://pokeapi.co/api/v2/pokemon/295/"
},
{
"name": "makuhita",
"url": "https://pokeapi.co/api/v2/pokemon/296/"
},
{
"name": "hariyama",
"url": "https://pokeapi.co/api/v2/pokemon/297/"
},
{
"name": "azurill",
"url": "https://pokeapi.co/api/v2/pokemon/298/"
},
{
"name": "nosepass",
"url": "https://pokeapi.co/api/v2/pokemon/299/"
},
{
"name": "skitty",
"url": "https://pokeapi.co/api/v2/pokemon/300/"
}
]
}*
FILTER FUNCTION
In your case, you should consider using .filter JS method to filter those elements that start with "a".
If you want both pokemons that starts with "a" or "b":
let pokemonStartingWithAorB = pokemonMock.results.filter(function(pokemon){
if(pokemon.name.startsWith("a") || pokemon.name.startsWith('b')){
return true;
}
return false;
});
If you want only pokemons that start with "a":
let pokemonStartingWithA = pokemonMock.results.filter(pokemon => pokemon.name.startsWith('a'));
The reference to the filter function: https://developer.mozilla.org/es/docs/Web/JavaScript/Referencia/Objetos_globales/Array/filter
Just loop the array, get the name and verify if it starts with a or b, if it does add to desired array.
const pokemonMock = {
"count": 1118,
"next": "https://pokeapi.co/api/v2/pokemon?offset=300&limit=100",
"previous": "https://pokeapi.co/api/v2/pokemon?offset=100&limit=100",
"results": [
{
"name": "unown",
"url": "https://pokeapi.co/api/v2/pokemon/201/"
},
{
"name": "wobbuffet",
"url": "https://pokeapi.co/api/v2/pokemon/202/"
},
{
"name": "girafarig",
"url": "https://pokeapi.co/api/v2/pokemon/203/"
},
{
"name": "pineco",
"url": "https://pokeapi.co/api/v2/pokemon/204/"
},
{
"name": "forretress",
"url": "https://pokeapi.co/api/v2/pokemon/205/"
},
{
"name": "dunsparce",
"url": "https://pokeapi.co/api/v2/pokemon/206/"
},
{
"name": "gligar",
"url": "https://pokeapi.co/api/v2/pokemon/207/"
},
{
"name": "steelix",
"url": "https://pokeapi.co/api/v2/pokemon/208/"
},
{
"name": "snubbull",
"url": "https://pokeapi.co/api/v2/pokemon/209/"
},
{
"name": "granbull",
"url": "https://pokeapi.co/api/v2/pokemon/210/"
},
{
"name": "qwilfish",
"url": "https://pokeapi.co/api/v2/pokemon/211/"
},
{
"name": "scizor",
"url": "https://pokeapi.co/api/v2/pokemon/212/"
},
{
"name": "shuckle",
"url": "https://pokeapi.co/api/v2/pokemon/213/"
},
{
"name": "heracross",
"url": "https://pokeapi.co/api/v2/pokemon/214/"
},
{
"name": "sneasel",
"url": "https://pokeapi.co/api/v2/pokemon/215/"
},
{
"name": "teddiursa",
"url": "https://pokeapi.co/api/v2/pokemon/216/"
},
{
"name": "ursaring",
"url": "https://pokeapi.co/api/v2/pokemon/217/"
},
{
"name": "slugma",
"url": "https://pokeapi.co/api/v2/pokemon/218/"
},
{
"name": "magcargo",
"url": "https://pokeapi.co/api/v2/pokemon/219/"
},
{
"name": "swinub",
"url": "https://pokeapi.co/api/v2/pokemon/220/"
},
{
"name": "piloswine",
"url": "https://pokeapi.co/api/v2/pokemon/221/"
},
{
"name": "corsola",
"url": "https://pokeapi.co/api/v2/pokemon/222/"
},
{
"name": "remoraid",
"url": "https://pokeapi.co/api/v2/pokemon/223/"
},
{
"name": "octillery",
"url": "https://pokeapi.co/api/v2/pokemon/224/"
},
{
"name": "delibird",
"url": "https://pokeapi.co/api/v2/pokemon/225/"
},
{
"name": "mantine",
"url": "https://pokeapi.co/api/v2/pokemon/226/"
},
{
"name": "skarmory",
"url": "https://pokeapi.co/api/v2/pokemon/227/"
},
{
"name": "houndour",
"url": "https://pokeapi.co/api/v2/pokemon/228/"
},
{
"name": "houndoom",
"url": "https://pokeapi.co/api/v2/pokemon/229/"
},
{
"name": "kingdra",
"url": "https://pokeapi.co/api/v2/pokemon/230/"
},
{
"name": "phanpy",
"url": "https://pokeapi.co/api/v2/pokemon/231/"
},
{
"name": "donphan",
"url": "https://pokeapi.co/api/v2/pokemon/232/"
},
{
"name": "porygon2",
"url": "https://pokeapi.co/api/v2/pokemon/233/"
},
{
"name": "stantler",
"url": "https://pokeapi.co/api/v2/pokemon/234/"
},
{
"name": "smeargle",
"url": "https://pokeapi.co/api/v2/pokemon/235/"
},
{
"name": "tyrogue",
"url": "https://pokeapi.co/api/v2/pokemon/236/"
},
{
"name": "hitmontop",
"url": "https://pokeapi.co/api/v2/pokemon/237/"
},
{
"name": "smoochum",
"url": "https://pokeapi.co/api/v2/pokemon/238/"
},
{
"name": "elekid",
"url": "https://pokeapi.co/api/v2/pokemon/239/"
},
{
"name": "magby",
"url": "https://pokeapi.co/api/v2/pokemon/240/"
},
{
"name": "miltank",
"url": "https://pokeapi.co/api/v2/pokemon/241/"
},
{
"name": "blissey",
"url": "https://pokeapi.co/api/v2/pokemon/242/"
},
{
"name": "raikou",
"url": "https://pokeapi.co/api/v2/pokemon/243/"
},
{
"name": "entei",
"url": "https://pokeapi.co/api/v2/pokemon/244/"
},
{
"name": "suicune",
"url": "https://pokeapi.co/api/v2/pokemon/245/"
},
{
"name": "larvitar",
"url": "https://pokeapi.co/api/v2/pokemon/246/"
},
{
"name": "pupitar",
"url": "https://pokeapi.co/api/v2/pokemon/247/"
},
{
"name": "tyranitar",
"url": "https://pokeapi.co/api/v2/pokemon/248/"
},
{
"name": "lugia",
"url": "https://pokeapi.co/api/v2/pokemon/249/"
},
{
"name": "ho-oh",
"url": "https://pokeapi.co/api/v2/pokemon/250/"
},
{
"name": "celebi",
"url": "https://pokeapi.co/api/v2/pokemon/251/"
},
{
"name": "treecko",
"url": "https://pokeapi.co/api/v2/pokemon/252/"
},
{
"name": "grovyle",
"url": "https://pokeapi.co/api/v2/pokemon/253/"
},
{
"name": "sceptile",
"url": "https://pokeapi.co/api/v2/pokemon/254/"
},
{
"name": "torchic",
"url": "https://pokeapi.co/api/v2/pokemon/255/"
},
{
"name": "combusken",
"url": "https://pokeapi.co/api/v2/pokemon/256/"
},
{
"name": "blaziken",
"url": "https://pokeapi.co/api/v2/pokemon/257/"
},
{
"name": "mudkip",
"url": "https://pokeapi.co/api/v2/pokemon/258/"
},
{
"name": "marshtomp",
"url": "https://pokeapi.co/api/v2/pokemon/259/"
},
{
"name": "swampert",
"url": "https://pokeapi.co/api/v2/pokemon/260/"
},
{
"name": "poochyena",
"url": "https://pokeapi.co/api/v2/pokemon/261/"
},
{
"name": "mightyena",
"url": "https://pokeapi.co/api/v2/pokemon/262/"
},
{
"name": "zigzagoon",
"url": "https://pokeapi.co/api/v2/pokemon/263/"
},
{
"name": "linoone",
"url": "https://pokeapi.co/api/v2/pokemon/264/"
},
{
"name": "wurmple",
"url": "https://pokeapi.co/api/v2/pokemon/265/"
},
{
"name": "silcoon",
"url": "https://pokeapi.co/api/v2/pokemon/266/"
},
{
"name": "beautifly",
"url": "https://pokeapi.co/api/v2/pokemon/267/"
},
{
"name": "cascoon",
"url": "https://pokeapi.co/api/v2/pokemon/268/"
},
{
"name": "dustox",
"url": "https://pokeapi.co/api/v2/pokemon/269/"
},
{
"name": "lotad",
"url": "https://pokeapi.co/api/v2/pokemon/270/"
},
{
"name": "lombre",
"url": "https://pokeapi.co/api/v2/pokemon/271/"
},
{
"name": "ludicolo",
"url": "https://pokeapi.co/api/v2/pokemon/272/"
},
{
"name": "seedot",
"url": "https://pokeapi.co/api/v2/pokemon/273/"
},
{
"name": "nuzleaf",
"url": "https://pokeapi.co/api/v2/pokemon/274/"
},
{
"name": "shiftry",
"url": "https://pokeapi.co/api/v2/pokemon/275/"
},
{
"name": "taillow",
"url": "https://pokeapi.co/api/v2/pokemon/276/"
},
{
"name": "swellow",
"url": "https://pokeapi.co/api/v2/pokemon/277/"
},
{
"name": "wingull",
"url": "https://pokeapi.co/api/v2/pokemon/278/"
},
{
"name": "pelipper",
"url": "https://pokeapi.co/api/v2/pokemon/279/"
},
{
"name": "ralts",
"url": "https://pokeapi.co/api/v2/pokemon/280/"
},
{
"name": "kirlia",
"url": "https://pokeapi.co/api/v2/pokemon/281/"
},
{
"name": "gardevoir",
"url": "https://pokeapi.co/api/v2/pokemon/282/"
},
{
"name": "surskit",
"url": "https://pokeapi.co/api/v2/pokemon/283/"
},
{
"name": "masquerain",
"url": "https://pokeapi.co/api/v2/pokemon/284/"
},
{
"name": "shroomish",
"url": "https://pokeapi.co/api/v2/pokemon/285/"
},
{
"name": "breloom",
"url": "https://pokeapi.co/api/v2/pokemon/286/"
},
{
"name": "slakoth",
"url": "https://pokeapi.co/api/v2/pokemon/287/"
},
{
"name": "vigoroth",
"url": "https://pokeapi.co/api/v2/pokemon/288/"
},
{
"name": "slaking",
"url": "https://pokeapi.co/api/v2/pokemon/289/"
},
{
"name": "nincada",
"url": "https://pokeapi.co/api/v2/pokemon/290/"
},
{
"name": "ninjask",
"url": "https://pokeapi.co/api/v2/pokemon/291/"
},
{
"name": "shedinja",
"url": "https://pokeapi.co/api/v2/pokemon/292/"
},
{
"name": "whismur",
"url": "https://pokeapi.co/api/v2/pokemon/293/"
},
{
"name": "loudred",
"url": "https://pokeapi.co/api/v2/pokemon/294/"
},
{
"name": "exploud",
"url": "https://pokeapi.co/api/v2/pokemon/295/"
},
{
"name": "makuhita",
"url": "https://pokeapi.co/api/v2/pokemon/296/"
},
{
"name": "hariyama",
"url": "https://pokeapi.co/api/v2/pokemon/297/"
},
{
"name": "azurill",
"url": "https://pokeapi.co/api/v2/pokemon/298/"
},
{
"name": "nosepass",
"url": "https://pokeapi.co/api/v2/pokemon/299/"
},
{
"name": "skitty",
"url": "https://pokeapi.co/api/v2/pokemon/300/"
}
]
}
const namePokemons = {
"a": [],
"b": []
};
pokemonMock.results.forEach(element => {
let name = element.name;
if(name.charAt(0) == 'a') {
namePokemons.a.push(name);
}
if(name.charAt(0) == 'b') {
namePokemons.b.push(name);
}
});
console.log(`name pokemons start with "a": ${namePokemons.a}`);
console.log(`name pokemons start with "b": ${namePokemons.b}`);
let obj = {
"options": [
{
"id": "a",
"name": "a",
"options": [
{
"id": "a.1",
"options": [
{
"id": "a.1.1",
"name": "a.1.1"
},
{
"id": "a.1.2",
"name": "a.1.2"
},
{
"id": "a.1.3",
"name": "a.1.3"
}
]
},
{
"id": "a.2",
"name": "a.2",
"options": [
{
"id": "a.2.1",
"name": "a.2.1"
},
{
"id": "a.2.2",
"name": "a.2.2"
},
{
"id": "a.2.3",
"name": "a.2.3"
}
]
},
{
"id": "a.3",
"name": "a.3",
"options": [
{
"id": "a.3.1",
"name": "a.3.1"
},
{
"id": "a.3.2",
"name": "a.3.1"
},
{
"id": "a.3.3",
"name": "a.3.1"
}
]
}
]
},
{
"name": "b",
"id": "b",
"options": [
{
"id": "b.1",
"name": "b.1",
"options": [
{
"id": "b.1.1",
"name": "b.1.1"
},
{
"id": "b.1.2",
"name": "b.1.2"
},
{
"id": "b.1.3",
"name": "b.1.3"
}
]
},
{
"id": "b.2",
"name": "b.2",
"options": [
{
"id": "b.2.1",
"name": "b.2.1"
},
{
"id": "b.2.2",
"name": "b.2.2"
},
{
"id": "b.2.3",
"name": "b.2.3"
}
]
},
{
"id": "b.3",
"name": "b.3.1",
"options": [
{
"id": "b.3.1",
"name": "b.3.1"
},
{
"id": "b.3.2",
"name": "b.3.2"
},
{
"id": "b.3.3",
"name": "b.3.3"
}
]
}
]
},
{
"id": "c",
"name": "c",
"options": [
{
"id": "c.1",
"name": "c.1",
"options": [
{
"id": "c.1.1",
"name": "c.1.1"
},
{
"id": "c.1.2",
"name": "c.1.2"
},
{
"id": "c.1.3",
"name": "c.1.3"
}
]
},
{
"id": "c.2",
"name": "c.2",
"options": [
{
"id": "c.2.1",
"name": "c.2.1"
},
{
"id": "c.2.2",
"name": "c.2.2"
},
{
"id": "c.2.3",
"name": "c.2.3"
}
]
},
{
"id": "c.3",
"name": "c.3",
"options": [
{
"id": "c.3.1",
"name": "c.3.1"
},
{
"id": "c.3.2",
"name": "c.3.2"
},
{
"id": "c.3.3",
"name": "c.3.3"
}
]
}
]
}
]
}
" I have this object
I neeed to create a function getHierarchy, that an option ID as its input, finds the option in the
list and returns the ID of all it's parents.
for example,getHierarchy("a.1.3") should return the following result ["a","a.1","a.1.3"]
getHierarchy("c.3.3") should return the following result ["c","c.3","c.3.3"] "
assuming id is unique;
function getHierarchy(object, id, prev) {
if (!object.options) return;
for (const child of object.options) {
if(child.id === id) {
return [...prev, object.id, child.id];
}
result = getHierarchy(child, id, [...prev, object.id]);
if (result) return result;
}
}
getHierarchy(obj, "a.1.3", []);
Here an recursive solution i hope this helps you.
let obj = {
"options": [
{
"id": "a",
"name": "a",
"options": [
{
"id": "a.1",
"options": [
{
"id": "a.1.1",
"name": "a.1.1"
},
{
"id": "a.1.2",
"name": "a.1.2"
},
{
"id": "a.1.3",
"name": "a.1.3"
}
]
},
{
"id": "a.2",
"name": "a.2",
"options": [
{
"id": "a.2.1",
"name": "a.2.1"
},
{
"id": "a.2.2",
"name": "a.2.2"
},
{
"id": "a.2.3",
"name": "a.2.3"
}
]
},
{
"id": "a.3",
"name": "a.3",
"options": [
{
"id": "a.3.1",
"name": "a.3.1"
},
{
"id": "a.3.2",
"name": "a.3.1"
},
{
"id": "a.3.3",
"name": "a.3.1"
}
]
}
]
},
{
"name": "b",
"id": "b",
"options": [
{
"id": "b.1",
"name": "b.1",
"options": [
{
"id": "b.1.1",
"name": "b.1.1"
},
{
"id": "b.1.2",
"name": "b.1.2"
},
{
"id": "b.1.3",
"name": "b.1.3"
}
]
},
{
"id": "b.2",
"name": "b.2",
"options": [
{
"id": "b.2.1",
"name": "b.2.1"
},
{
"id": "b.2.2",
"name": "b.2.2"
},
{
"id": "b.2.3",
"name": "b.2.3"
}
]
},
{
"id": "b.3",
"name": "b.3.1",
"options": [
{
"id": "b.3.1",
"name": "b.3.1"
},
{
"id": "b.3.2",
"name": "b.3.2"
},
{
"id": "b.3.3",
"name": "b.3.3"
}
]
}
]
},
{
"id": "c",
"name": "c",
"options": [
{
"id": "c.1",
"name": "c.1",
"options": [
{
"id": "c.1.1",
"name": "c.1.1"
},
{
"id": "c.1.2",
"name": "c.1.2"
},
{
"id": "c.1.3",
"name": "c.1.3"
}
]
},
{
"id": "c.2",
"name": "c.2",
"options": [
{
"id": "c.2.1",
"name": "c.2.1"
},
{
"id": "c.2.2",
"name": "c.2.2"
},
{
"id": "c.2.3",
"name": "c.2.3"
}
]
},
{
"id": "c.3",
"name": "c.3",
"options": [
{
"id": "c.3.1",
"name": "c.3.1"
},
{
"id": "c.3.2",
"name": "c.3.2"
},
{
"id": "c.3.3",
"name": "c.3.3"
}
]
}
]
}
]
}
function getHierarchy(opts, path, index = 1, result = []) {
if(!opts) return result;
let objPaths = path.split(".");
let _path = objPaths.slice(0, index).join(".");
let option = opts.find(({id}) => id === _path);
if(!option) return result;
let { options, id } = option;
return getHierarchy(options, path, ++index, [...result,id]);
}
let result = getHierarchy(obj.options, "a.1.3");
console.log(result);
I have a role-template array that gives each role a name, and a description. It also has a nested object with an array of permissions that are identified by id.
{
"data": [
{
"id": "1",
"type": "role-templates",
"attributes": {
"name": "Org Admin"
},
"relationships": {
"permissions": {
"data": [
{ "type": "permissions", "id": "1" },
{ "type": "permissions", "id": "2" },
{ "type": "permissions", "id": "3" },
{ "type": "permissions", "id": "4" },
{ "type": "permissions", "id": "5" },
{ "type": "permissions", "id": "6" },
{ "type": "permissions", "id": "7" },
{ "type": "permissions", "id": "8" },
{ "type": "permissions", "id": "9" },
{ "type": "permissions", "id": "10" },
{ "type": "permissions", "id": "11" },
{ "type": "permissions", "id": "12" },
{ "type": "permissions", "id": "13" },
{ "type": "permissions", "id": "14" },
{ "type": "permissions", "id": "15" },
{ "type": "permissions", "id": "17" },
{ "type": "permissions", "id": "18" },
{ "type": "permissions", "id": "19" },
{ "type": "permissions", "id": "20" },
{ "type": "permissions", "id": "21" },
{ "type": "permissions", "id": "23" },
{ "type": "permissions", "id": "24" }
]
}
}
},
{
"id": "2",
"type": "role-templates",
"attributes": { "name": "Data Admin" },
"relationships": {
"permissions": {
"data": [
{ "type": "permissions", "id": "1" },
{ "type": "permissions", "id": "2" },
{ "type": "permissions", "id": "3" },
{ "type": "permissions", "id": "4" },
{ "type": "permissions", "id": "5" },
{ "type": "permissions", "id": "6" }
]
}
}
},
{
"id": "3",
"type": "role-templates",
"attributes": {
"name": "Setup Admin"
},
"relationships": {
"permissions": {
"data": [{ "type": "permissions", "id": "8" }]
}
}
},
{
"id": "4",
"type": "role-templates",
"attributes": { "name": "Data Consumer"},
"relationships": {
"permissions": {
"data": [
{ "type": "permissions", "id": "11" },
{ "type": "permissions", "id": "13" }
]
}
}
},
{
"id": "5",
"type": "role-templates",
"attributes": { "name": "APT User" },
"relationships": {
"permissions": {
"data": [
{ "type": "permissions", "id": "17" },
{ "type": "permissions", "id": "18" },
{ "type": "permissions", "id": "19" }
]
}
}
},
{
"id": "6",
"type": "role-templates",
"attributes": {
"name": "User Admin"
},
"relationships": {
"permissions": {
"data": [
{ "type": "permissions", "id": "21" },
{ "type": "permissions", "id": "23" }
]
}
}
}
],
"meta": { "record-count": 6 }
}
Now I have a permissions array that gives each permission a name, and an id. That id can be matched to the nested array in the role-template array. I want to match these two arrays by the permission.id property that each of these arrays posses. Then for each role that has a permission. I want to display an asterisk * for this
How can I do that?
[
{
"id": "1",
"type": "permissions",
"attributes": {
"name": "Administer Source List",
},
"relationships": {
"roles": {
"data": [
{ "type": "roles", "id": "1" },
{ "type": "roles", "id": "2" },
{ "type": "roles", "id": "7" },
{ "type": "roles", "id": "8" }
]
}
}
},
{
"id": "2",
"type": "permissions",
"attributes": {
"name": "Administer Common Layers",
},
"relationships": {
"roles": {
"data": [
{ "type": "roles", "id": "1" },
{ "type": "roles", "id": "2" },
{ "type": "roles", "id": "7" },
{ "type": "roles", "id": "8" }
]
}
}
},
{
"id": "3",
"type": "permissions",
"attributes": {
"name": "Do benchmark tagging"
},
"relationships": {
"roles": {
"data": [
{ "type": "roles", "id": "1" },
{ "type": "roles", "id": "2" },
{ "type": "roles", "id": "7" },
{ "type": "roles", "id": "8" }
]
}
}
},
{
"id": "4",
"type": "permissions",
"attributes": {
"name": "Do trend mapping"
},
"relationships": {
"roles": {
"data": [
{ "type": "roles", "id": "1" },
{ "type": "roles", "id": "2" },
{ "type": "roles", "id": "7" },
{ "type": "roles", "id": "8" }
]
}
}
},
{
"id": "5",
"type": "permisns",
"attributes": {
"name": "Map custom values (for each data source)"
},
"relationships": {
"roles": {
"data": [
{ "type": "roles", "id": "1" },
{ "type": "roles", "id": "2" },
{ "type": "roles", "id": "7" },
{ "type": "roles", "id": "8" }
]
}
}
},
{
"id": "6",
"type": "permissions",
"attributes": {
"name": "Administer Data Sets"
},
"relationships": {
"roles": {
"data": [
{ "type": "roles", "id": "1" },
{ "type": "roles", "id": "2" },
{ "type": "roles", "id": "7" },
{ "type": "roles", "id": "8" }
]
}
}
},
{
"id": "7",
"type": "permisns"
"attributes": {
"name": "Create Campaigns"
},
"relationships": {
"roles": {
"data": [{ "type": "roles", "id": "1" }, { "type": "roles", "id": "7" }]
}
}
},
{
"id": "8",
"type": "permissions",
"attributes": {
"name": "Access/modify campaign setup"
},
"relationships": {
"roles": {
"data": [
{ "type": "roles", "id": "1" },
{ "type": "roles", "id": "3" },
{ "type": "roles", "id": "7" },
{ "type": "roles", "id": "9" }
]
}
}
},
{
"id": "9",
"type": "permissions",
"attributes": {
"name": "Launch campaigns"
},
"relationships": {
"roles": {
"data": [{ "type": "roles", "id": "1" }, { "type": "roles", "id": "7" }]
}
}
},
{
"id": "10",
"type": "permissions",
"attributes": {
"name": "Create org-wide survey-related notifications"
},
"relationships": {
"roles": {
"data": [{ "type": "roles", "id": "1" }, { "type": "roles", "id": "7" }]
}
}
},
{
"id": "11",
"type": "permissions",
"attributes": {
"name": "View Reports"
},
"relationships": {
"roles": {
"data": [
{ "type": "roles", "id": "1" },
{ "type": "roles", "id": "4" },
{ "type": "roles", "id": "7" },
{ "type": "roles", "id": "10" }
]
}
}
},
{
"id": "12",
"type": "permissions",
"attributes": {
"name": "Modify prebuilt reports"
},
"relationships": {
"roles": {
"data": [{ "type": "roles", "id": "1" }, { "type": "roles", "id": "7" }]
}
}
},
{
"id": "13",
"type": "permissions",
"attributes": {
"name": "Create new reports"
},
"relationships": {
"roles": {
"data": [
{ "type": "roles", "id": "1" },
{ "type": "roles", "id": "4" },
{ "type": "roles", "id": "7" },
{ "type": "roles", "id": "10" }
]
}
}
},
{
"id": "14",
"type": "permissions",
"attributes": {
"name": "Share reports with rest of org"
},
"relationships": {
"roles": {
"data": [{ "type": "roles", "id": "1" }, { "type": "roles", "id": "7" }]
}
}
},
{
"id": "15",
"type": "permissions",
"attributes": {
"name": "Share filters with rest of org"
},
"relationships": {
"roles": {
"data": [{ "type": "roles", "id": "1" }, { "type": "roles", "id": "7" }]
}
}
},
{
"id": "16",
"type": "permissions",
"attributes": {
"name": "Create portfolio"
},
"relationships": {
"roles": {
"data": []
}
}
},
{
"id": "17",
"type": "permissions",
"attributes": {
"name": "Access all portfolios (at org)"
},
"relationships": {
"roles": {
"data": [
{ "type": "roles", "id": "1" },
{ "type": "roles", "id": "5" },
{ "type": "roles", "id": "7" },
{ "type": "roles", "id": "11" }
]
}
}
},
{
"id": "18",
"type": "permissions",
"attributes": {
"name": "Assign action plans"
},
"relationships": {
"roles": {
"data": [
{ "type": "roles", "id": "1" },
{ "type": "roles", "id": "5" },
{ "type": "roles", "id": "7" },
{ "type": "roles", "id": "11" }
]
}
}
},
{
"id": "19",
"type": "permissions",
"attributes": {
"name": "Work on action plans"
},
"relationships": {
"roles": {
"data": [
{ "type": "roles", "id": "1" },
{ "type": "roles", "id": "5" },
{ "type": "roles", "id": "7" },
{ "type": "roles", "id": "11" }
]
}
}
},
{
"id": "20",
"type": "permissions",
"attributes": {
"name": "Administer role templates for org"
},
"relationships": {
"roles": {
"data": [{ "type": "roles", "id": "1" }, { "type": "roles", "id": "7" }]
}
}
},
{
"id": "21",
"type": "permissions",
"attributes": {
"name": "Add/edit/delete non org-admin users at org"
},
"relationships": {
"roles": {
"data": [
{ "type": "roles", "id": "1" },
{ "type": "roles", "id": "6" },
{ "type": "roles", "id": "7" },
{ "type": "roles", "id": "12" }
]
}
}
},
{
"id": "22",
"type": "permissions",
"attributes": {
"name": "Add/edit/dete ORg Admin users at org"
},
"relationships": {
"roles": {
"data": []
}
}
},
{
"id": "23",
"type": "permissions",
"attributes": {
"name": "Administer access patterns at org"
},
"relationships": {
"roles": {
"data": [
{ "type": "roles", "id": "1" },
{ "type": "roles", "id": "6" },
{ "type": "roles", "id": "7" },
{ "type": "roles", "id": "12" }
]
}
}
},
{
"id": "24",
"type": "permissions",
"attributes": {
"name": "Switch user (\"Impersonate\" another user)"
},
"relationships": {
"roles": {
"data": [{ "type": "roles", "id": "1" }, { "type": "roles", "id": "7" }]
}
}
}
]
My react table looks like this right now:
What I want to do is to put an asterisk * in every cell for the permission that each role has.
My React component currently looks like this:
class SystemRoleTemplatesContainer extends React.Component {
constructor(props) {
super(props);
this.state = {
isLoading: false,
permissionList: [],
roleTemplateList: [],
permissionsGroup: []
};
}
componentDidMount = () => {
this.getTableData();
}
getTableData = () => {
store.dispatch(api.getRoletemplates()).then((result) => {
const permissionHeader = [{
Header: "Permissions",
accessor: "permission"
}]
const roleTemplateItems = result.body.data.map((data) => {
return {
id: data.relationships.permissions.data.map((data)=>{
return {
id: data.id
}
}),
Header: data.attributes.name,
accessor: data.attributes.name.replace(/\s/g, '')
}
});
const roleTemplate = permissionHeader.concat(roleTemplateItems)
this.setState(() => ({
"roleTemplateList": roleTemplate
}));
});
store.dispatch(api.getPermissions()).then((result) => {
const permissionItems = result.body.data.map((data) => {
return {
id: data.id,
permission: data.attributes.name
}
});
this.setState(() => ({
"permissionList": permissionItems
}));
});
}
render() {
const {isLoading,roleTemplateList, permissionList} = this.state;
if (isLoading) {
return <LoadingAnimation />;
}
return (
<div className="role-management-form">
<div className="admin-user-container-title">
<Row>
<Col md={8}>
<h3>Manage Roles Template for System</h3>
</Col>
</Row>
</div>
<Table
columns={roleTemplateList}
className="organization-tbl"
data={permissionList}
defaultPageSize={50}
minRows={0}
/>
</div>
);
}
}
So I was able to use lodash to accomplish this.
class SystemRoleTemplatesContainer extends React.Component {
constructor(props) {
super(props);
this.state = {
isLoading: false,
permissionList: [],
roleTemplateList: []
};
}
componentDidMount = () => {
this.getTableData();
}
getTableData = () => {
store.dispatch(api.getRoletemplates()).then((result) => {
const permissionHeader = [{
Header: "Permissions",
accessor: "permission"
}]
const roleTemplateItems = result.body.data.map((data) => {
return {
id: data.relationships.permissions.data.map((data)=>{
return {
id: data.id
}
}),
Header: data.attributes.name,
accessor: data.attributes.name.replace(/\s/g, '')
}
});
const roleTemplate = permissionHeader.concat(roleTemplateItems)
this.setState(() => ({
"roleTemplateList": roleTemplate
}));
});
store.dispatch(api.getPermissions()).then((result) => {
const permissionItems = result.body.data.map((data) => {
return {
id: data.id,
permission: data.attributes.name
}
});
this.setState(() => ({
"permissionList": permissionItems
}));
});
}
render() {
const {isLoading,roleTemplateList, permissionList} = this.state;
const updatedList = permissionList.map(permission => {
return roleTemplateList.reduce((permAcc, role) => {
const match = _.find(role.id, {'id': permAcc.id});
if(typeof match !== 'undefined' && role.accessor !== 'permission') {
permAcc[role.accessor] = '*';
} else if(role.accessor !== 'permission') {
permAcc[role.accessor] = '';
}
return permAcc;
}, permission);
});
if (isLoading) {
return <LoadingAnimation />;
}
return (
<div className="role-management-form">
<div className="admin-user-container-title">
<Row>
<Col md={8}>
<h3>Manage Roles Template for System</h3>
</Col>
</Row>
</div>
<Table
columns={roleTemplateList}
className="organization-tbl"
data={updatedList}
defaultPageSize={50}
minRows={0}
/>
</div>
);
}
}
I'm having problems with my code, where I need to pick data with a JSON query from an API.
Here is the JSON body what I receive from the query:
{
"status": "success",
"reservations": [
{
"id": "38199",
"subject": "Koneiden vaihto",
"modifiedDate": "2017-05-16T12:46:17",
"startDate": "2017-06-21T08:00:00",
"endDate": "2017-06-21T22:00:00",
"resources": [
{
"id": "124",
"type": "room",
"code": "FRAMIF407",
"parent": {
"id": "4",
"type": "building",
"code": "FramiF",
"name": "Frami F"
},
"name": "Frami F407 (atk 34)"
}
],
"description": ""
},
{
"id": "30505",
"subject": "Alumnitapahtuman etukäteisjärjestelyt",
"modifiedDate": "2017-04-19T09:36:02",
"startDate": "2017-06-21T08:00:00",
"endDate": "2017-06-21T22:00:00",
"resources": [
{
"id": "104",
"type": "room",
"code": "FRAMIF144",
"parent": {
"id": "4",
"type": "building",
"code": "FramiF",
"name": "Frami F"
},
"name": "Frami F144 (lasipalatsi 120)"
}
],
"description": ""
},
{
"id": "38864",
"subject": "Koneiden vaihto/säilytystila",
"modifiedDate": "2017-06-21T06:03:07",
"startDate": "2017-06-21T08:00:00",
"endDate": "2017-06-21T22:00:00",
"resources": [
{
"id": "107",
"type": "room",
"code": "FRAMIF211",
"parent": {
"id": "4",
"type": "building",
"code": "FramiF",
"name": "Frami F"
},
"name": "Frami F211 (fysioterapia/teoria)"
}
],
"description": ""
},
{
"id": "38335",
"subject": "Koneiden vaihto",
"modifiedDate": "2017-05-16T12:48:32",
"startDate": "2017-06-21T08:00:00",
"endDate": "2017-06-21T22:00:00",
"resources": [
{
"id": "127",
"type": "room",
"code": "FRAMIF410",
"parent": {
"id": "4",
"type": "building",
"code": "FramiF",
"name": "Frami F"
},
"name": "Frami F410 (atk 34)"
}
],
"description": ""
},
{
"id": "38426",
"subject": "Koneiden vaihto",
"modifiedDate": "2017-05-16T12:49:25",
"startDate": "2017-06-21T08:00:00",
"endDate": "2017-06-21T22:00:00",
"resources": [
{
"id": "128",
"type": "room",
"code": "FRAMIF411",
"parent": {
"id": "4",
"type": "building",
"code": "FramiF",
"name": "Frami F"
},
"name": "Frami F411 (atk 34)"
}
],
"description": ""
},
{
"id": "43898",
"subject": "Varattu plinttien varastointiin",
"modifiedDate": "2017-06-12T08:54:31",
"startDate": "2017-06-21T08:00:00",
"endDate": "2017-06-21T22:00:00",
"resources": [
{
"id": "106",
"type": "room",
"code": "FRAMIF210",
"parent": {
"id": "4",
"type": "building",
"code": "FramiF",
"name": "Frami F"
},
"name": "Frami F210 (teoria 36)"
}
],
"description": ""
},
{
"id": "38267",
"subject": "Koneiden vaihto",
"modifiedDate": "2017-06-21T06:03:07",
"startDate": "2017-06-21T08:00:00",
"endDate": "2017-06-21T22:00:00",
"resources": [
{
"id": "126",
"type": "room",
"code": "FRAMIF409",
"parent": {
"id": "4",
"type": "building",
"code": "FramiF",
"name": "Frami F"
},
"name": "Frami F409 (atk 34)"
}
],
"description": ""
}
]
}
I need to pick up the all the names from the body, which are for example :
"Frami F407 (atk 34)", "Frami F144 (lasipalatsi 120)",
"Frami F211 (fysioterapia/teoria)", "Frami F410 (atk 34)
Here's how I process the data in order to get the names;
var jsonQuery = {
"startDate": startDate,
"endDate": endDate,
"building": [building]
};
var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function () {
if (xhr.readyState == 4 && xhr.status == 200) {
var json = JSON.parse(xhr.responseText);
console.log(xhr.responseText);
var rooms = [];
for (var i = 0; i < json.reservations.length; i++) {
if (json.reservations[i].resources != null) {
for (var j = 0; j < json.reservations[i].resources.length; j++) {
var reservation = json.reservations[i];
var resource = json.reservations[i].resources[j];
if (resource.type === "room") {
if (rooms.indexOf("code")) {
rooms.push(resource.name);
}
}
}
}
}
}
};
xhr.open("POST", "URL", true, "API-key", "");
xhr.setRequestHeader('Content-Type', 'application/json');
xhr.send(JSON.stringify(jsonQuery));
This is how it should work : https://jsfiddle.net/p474djan/3/
But the problem is, when I run it through JSON.parse() and check in the console log, it keeps the first two names ("Frami F407 (atk 34)" and "Frami F144 (lasipalatsi 120)") but removes all the rest of the names. Any idea why this is happening?
I am not able to find any issue on your code but here it is my suggestion you can achieve the same via underscore.js without any looping and so on
https://jsfiddle.net/p474djan/5/
document.getElementById("pageOne").innerHTML = _.pluck(_.flatten(_.pluck(json["reservations"], 'resources')), 'name').join("<br/>")
Please have a look in to this
I have been using nested loops to access data of the json object to display the id and type of topping, however its not working. Here's my code:
var j_obj = {
"id": "0001",
"type": "donut",
"name": "Cake",
"ppu": 0.55,
"batters": {
"batter": [{
"id": "1001",
"type": "Regular"
}, {
"id": "1002",
"type": "Chocolate"
}, {
"id": "1003",
"type": "Blueberry"
}, {
"id": "1004",
"type": "Devil's Food"
}]
},
"topping": [{
"id": "5001",
"type": "None"
}, {
"id": "5002",
"type": "Glazed"
}, {
"id": "5005",
"type": "Sugar"
}, {
"id": "5007",
"type": "Powdered Sugar"
}, {
"id": "5006",
"type": "Chocolate with Sprinkles"
}, {
"id": "5003",
"type": "Chocolate"
}, {
"id": "5004",
"type": "Maple"
}]
}
var Outer_log=[];
debugger
angular.forEach(j_obj, function(an_object){
//Outer_log.push("ID : "+an_object.id+" type : "+an_object.type);
angular.forEach(an_object.topping,function(innerobject){
Outer_log.push("ID : "+innerobject.id+" type : "+innerobject.type);
},Outer_log);
});
console.log(Outer_log);
Could someone please highlight the error in above code, Thanks
Without using nested loop you can iterate using angular.forEach like this
var finalArray=[];
angular.forEach(j_obj[0].topping, function(eachobject){
finalArray.push("ID : "+ eachobject.id+" type : "+ eachobject.type);
});
Angulars forEach is intended to iterate over arrays not object. so if you change your code to something like this
var j_obj = [{ ...}] //object is wrapped inside array.
it will work. Another thing is you don't need a nested loop in this case. You can just do:
angular.forEach(j_obj.topping, function(key, value){ ... });
you are iterating over object where as loop run over array.
hope this helps JSfiddle link
var j_obj = [{
"id": "0001",
"type": "donut",
"name": "Cake",
"ppu": 0.55,
"batters": {
"batter": [{
"id": "1001",
"type": "Regular"
}, {
"id": "1002",
"type": "Chocolate"
}, {
"id": "1003",
"type": "Blueberry"
}, {
"id": "1004",
"type": "Devil's Food"
}]
},
"topping": [{
"id": "5001",
"type": "None"
}, {
"id": "5002",
"type": "Glazed"
}, {
"id": "5005",
"type": "Sugar"
}, {
"id": "5007",
"type": "Powdered Sugar"
}, {
"id": "5006",
"type": "Chocolate with Sprinkles"
}, {
"id": "5003",
"type": "Chocolate"
}, {
"id": "5004",
"type": "Maple"
}]
}]
var Outer_log = [];
angular.forEach(j_obj, function(an_object) {
//Outer_log.push("ID : "+an_object.id+" type : "+an_object.type);
angular.forEach(an_object.topping, function(innerobject) {
Outer_log.push("ID : " + innerobject.id + " type : " + innerobject.type);
}, Outer_log);
});
console.log(Outer_log);