Is there a particular way to join each individual block of string with | that way it’s
9000234|Test NPC|0|0|0|0|0|0|0|0| excluding isEnabled. I don’t want the other block merging with each other either. I’m not exactly sure how I would go about this.
"100_npc": {
"uniqueId": 9000234,
"username": "Test NPC",
"itemsObj": {"colour": 0, "head": 0, "face": 0, "body": 0, "neck": 0, "hand": 0, "feet": 0, "flag": 0, "photo": 0},
"isEnabled": true
},
"101_npc": {
"uniqueId": 9000251,
"username": "Pelican",
"itemsObj": {"colour": 0, "head": 0, "face": 0, "body": 0, "neck": 0, "hand": 0, "feet": 0, "flag": 0, "photo": 0},
"isEnabled": true
}
}
>Solution :
This seems to output what you are asking for: (playground)
let data = {
'100_npc': {
uniqueId: 9000234,
username: 'Test NPC',
itemsObj: {
colour: 0,
head: 0,
face: 0,
body: 0,
neck: 0,
hand: 0,
feet: 0,
flag: 0,
photo: 0,
},
isEnabled: true,
},
'101_npc': {
uniqueId: 9000251,
username: 'Pelican',
itemsObj: {
colour: 0,
head: 0,
face: 0,
body: 0,
neck: 0,
hand: 0,
feet: 0,
flag: 0,
photo: 0,
},
isEnabled: true,
},
};
let result = [];
for (let key in data) {
if (data.hasOwnProperty(key)) {
let item = data[key];
let arr = [item.uniqueId, item.username];
for (let objKey in item.itemsObj) {
arr.push(item.itemsObj[objKey]);
}
result.push(arr.join('|'));
}
}
console.log(result.join('\n'));