I have the following JSON (snippet):
"1": {
"Name": [
"Person1",
"Person2",
"Person3",
"Person4",
"Person5"
]
}
"4"{
"Name": [
"AnotherPerson1",
"AnotherPerson2",
"AnotherPerson3",
"AnotherPerson4",
"AnotherPerson5"
]
}
...
I don't know the key value (it doesn't increase linearly) and I don't know the different values inside "Name" (only that they are inside "Name", are strings, and total 5).
I want to return all first strings under "Name" and their respective root(?) key. So "Person1" & "1"; "AnotherPerson1" & "4", etc.
I've only managed to make it work when I know the key value but it's too long to write.
console.log(data[1]["Name"][1]);
var keys = Object.keys(data);
keys.forEach(function(key) {
console.log(data[key].Name[0], 'on root key', key);
});
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加