Get key/value pair from Firebase response nested JSON object
I am getting the following response from a GET API call to Firebase database. It is a nested JSON objects.
I want to get all the values for key name
from each nested object into an array using JavaScript
GET REST API Response:
{
"barID1": {
"address": "4 East Terrace, Sydney NSW 2000",
"appStoreURL": "http://itunes.apple.com/app/idXXXXXXXXX",
"description": “description text”,
"imgURLs": [ "Https:url1”, "https:url2”, "https:url3” ],
"lat": -34.810585,
"lon": 138.616739,
"name": "Africola",
"phone": "(08) 8223 3885",
"status": "active",
"venueImgURL": "https:url”
},
"barID2": {
"address": "138/140 Gouger St, Sydney NSW 2000",
"appStoreURL": "http://itunes.apple.com/app/idXXXXXXXXX",
"description": “description text”,
"imgURLs": [ "Https:url1”, "https:url2”, "https:url3” ],
"lat": -34.848082,
"lon": 138.599813,
"name": "Disco Mexico Taqueria",
"phone": "0416 855 108",
"status": "active",
"venueImgURL": "https:url”
}
}
javascript arrays json object
add a comment |
I am getting the following response from a GET API call to Firebase database. It is a nested JSON objects.
I want to get all the values for key name
from each nested object into an array using JavaScript
GET REST API Response:
{
"barID1": {
"address": "4 East Terrace, Sydney NSW 2000",
"appStoreURL": "http://itunes.apple.com/app/idXXXXXXXXX",
"description": “description text”,
"imgURLs": [ "Https:url1”, "https:url2”, "https:url3” ],
"lat": -34.810585,
"lon": 138.616739,
"name": "Africola",
"phone": "(08) 8223 3885",
"status": "active",
"venueImgURL": "https:url”
},
"barID2": {
"address": "138/140 Gouger St, Sydney NSW 2000",
"appStoreURL": "http://itunes.apple.com/app/idXXXXXXXXX",
"description": “description text”,
"imgURLs": [ "Https:url1”, "https:url2”, "https:url3” ],
"lat": -34.848082,
"lon": 138.599813,
"name": "Disco Mexico Taqueria",
"phone": "0416 855 108",
"status": "active",
"venueImgURL": "https:url”
}
}
javascript arrays json object
add a comment |
I am getting the following response from a GET API call to Firebase database. It is a nested JSON objects.
I want to get all the values for key name
from each nested object into an array using JavaScript
GET REST API Response:
{
"barID1": {
"address": "4 East Terrace, Sydney NSW 2000",
"appStoreURL": "http://itunes.apple.com/app/idXXXXXXXXX",
"description": “description text”,
"imgURLs": [ "Https:url1”, "https:url2”, "https:url3” ],
"lat": -34.810585,
"lon": 138.616739,
"name": "Africola",
"phone": "(08) 8223 3885",
"status": "active",
"venueImgURL": "https:url”
},
"barID2": {
"address": "138/140 Gouger St, Sydney NSW 2000",
"appStoreURL": "http://itunes.apple.com/app/idXXXXXXXXX",
"description": “description text”,
"imgURLs": [ "Https:url1”, "https:url2”, "https:url3” ],
"lat": -34.848082,
"lon": 138.599813,
"name": "Disco Mexico Taqueria",
"phone": "0416 855 108",
"status": "active",
"venueImgURL": "https:url”
}
}
javascript arrays json object
I am getting the following response from a GET API call to Firebase database. It is a nested JSON objects.
I want to get all the values for key name
from each nested object into an array using JavaScript
GET REST API Response:
{
"barID1": {
"address": "4 East Terrace, Sydney NSW 2000",
"appStoreURL": "http://itunes.apple.com/app/idXXXXXXXXX",
"description": “description text”,
"imgURLs": [ "Https:url1”, "https:url2”, "https:url3” ],
"lat": -34.810585,
"lon": 138.616739,
"name": "Africola",
"phone": "(08) 8223 3885",
"status": "active",
"venueImgURL": "https:url”
},
"barID2": {
"address": "138/140 Gouger St, Sydney NSW 2000",
"appStoreURL": "http://itunes.apple.com/app/idXXXXXXXXX",
"description": “description text”,
"imgURLs": [ "Https:url1”, "https:url2”, "https:url3” ],
"lat": -34.848082,
"lon": 138.599813,
"name": "Disco Mexico Taqueria",
"phone": "0416 855 108",
"status": "active",
"venueImgURL": "https:url”
}
}
javascript arrays json object
javascript arrays json object
edited 59 mins ago
Jack Bashford
8,53131539
8,53131539
asked 1 hour ago
RoggieRoggie
201112
201112
add a comment |
add a comment |
5 Answers
5
active
oldest
votes
It can be done using :
Using
Array.reduce
to accumulate thename
values into a single array.Using
Object.keys
andArray.map
to iterate through the keys and map it to thename
array.Using
Object.values
andArray.map
Using
Array.from
and utilizing the second mapping function parameter to map individual objects to an array ofnames
.
const obj = {"barID1":{"address":"4 East Terrace, Sydney NSW 2000","appStoreURL":"http://itunes.apple.com/app/idXXXXXXXXX","description":"description text","imgURLs":["Https:url1","https:url2","https:url3"],"lat":-34.810585,"lon":138.616739,"name":"Africola","phone":"(08) 8223 3885","status":"active","venueImgURL":"https:url"},"barID2":{"address":"138/140 Gouger St, Sydney NSW 2000","appStoreURL":"http://itunes.apple.com/app/idXXXXXXXXX","description":"description text","imgURLs":["Https:url1","https:url2","https:url3"],"lat":-34.848082,"lon":138.599813,"name":"Disco Mexico Taqueria","phone":"0416 855 108","status":"active","venueImgURL":"https:url"}};
//using Object.values & reduce
let name = Object.values(obj).reduce((acc, ele) =>{
return acc.concat(ele.name)
}, );
console.log(name);
//using Object.keys & map
name = Object.keys(obj).map((ele) => obj[ele]['name']);
console.log(name);
//using Object.values & map
name = Object.values(obj).map((ele) => ele.name);
console.log(name);
//using Array.from
name = Array.from(Object.values(obj), ele => ele.name);
console.log(name);
add a comment |
You could extract the values of the input object via Object.values()
and then map()
the name
from each object
value as shown below to achieve this:
const data = {
barID1: {
address: "4 East Terrace, Sydney NSW 2000",
appStoreURL: "http://itunes.apple.com/app/idXXXXXXXXX",
description: "description text",
imgURLs: [ "Https:url1", "https:url2", "https:url3" ],
lat: -34.810585,
lon: 138.616739,
name: "Africola",
phone: "(08) 8223 3885",
status: "active",
venueImgURL: "https:url"
},
barID2: {
address: "138/140 Gouger St, Sydney NSW 2000",
appStoreURL: "http://itunes.apple.com/app/idXXXXXXXXX",
description: "description text",
imgURLs: [ "Https:url1", "https:url2", "https:url3" ],
lat: -34.848082,
lon: 138.599813,
name: "Disco Mexico Taqueria",
phone: "0416 855 108",
status: "active",
venueImgURL: "https:url"
}
}
console.log( Object.values(data).map(object => object.name) )
add a comment |
Here I use for in
to loop each object in your JSON then push the name into the result array.
const data = {
"barID1": {
"address": "4 East Terrace, Sydney NSW 2000",
"appStoreURL": "http://itunes.apple.com/app/idXXXXXXXXX",
"description": "description text",
"imgURLs": ["Https:url1", "https: url2", "https:url3"],
"lat": -34.810585,
"lon": 138.616739,
"name": "Africola",
"phone": "(08) 8223 3885",
"status": "active",
"venueImgURL": "https:url"
},
"barID2": {
"address": "138/140 Gouger St, Sydney NSW 2000",
"appStoreURL": "http://itunes.apple.com/app/idXXXXXXXXX",
"description": "description text",
"imgURLs": ["Https:url1", "https: url2", "https:url3"],
"lat": -34.848082,
"lon": 138.599813,
"name": "Disco Mexico Taqueria",
"phone": "0416 855 108",
"status": "active",
"venueImgURL": "https:url"
}
}
let result =
for (let i in data) {
result.push(data[i].name)
}
console.log(result)
add a comment |
You can map() the Object.values() of the json structure.
const json = {
"barID1": {
"address": "4 East Terrace, Sydney NSW 2000",
"appStoreURL": "http://itunes.apple.com/app/idXXXXXXXXX",
"description": "description text",
"imgURLs": [ "Https:url1", "https:url2", "https:url3" ],
"lat": -34.810585,
"lon": 138.616739,
"name": "Africola",
"phone": "(08) 8223 3885",
"status": "active",
"venueImgURL": "https:url"
},
"barID2": {
"address": "138/140 Gouger St, Sydney NSW 2000",
"appStoreURL": "http://itunes.apple.com/app/idXXXXXXXXX",
"description": "description text",
"imgURLs": [ "Https:url1", "https:url2", "https:url3" ],
"lat": -34.848082,
"lon": 138.599813,
"name": "Disco Mexico Taqueria",
"phone": "0416 855 108",
"status": "active",
"venueImgURL": "https:url"
}
};
let res = Object.values(json).map(({name}) => name);
console.log(res);
add a comment |
The simplest solution is Object.values
:
const data = {"barID1":{"address":"4 East Terrace, Sydney NSW 2000","appStoreURL":"http://itunes.apple.com/app/idXXXXXXXXX","description":"description text","imgURLs":["Https:url1","https:url2","https:url3"],"lat":-34.810585,"lon":138.616739,"name":"Africola","phone":"(08) 8223 3885","status":"active","venueImgURL":"https:url"},"barID2":{"address":"138/140 Gouger St, Sydney NSW 2000","appStoreURL":"http://itunes.apple.com/app/idXXXXXXXXX","description":"description text","imgURLs":["Https:url1","https:url2","https:url3"],"lat":-34.848082,"lon":138.599813,"name":"Disco Mexico Taqueria","phone":"0416 855 108","status":"active","venueImgURL":"https:url"}};
const namesArr = Object.values(data).map(({ name }) => name);
console.log(namesArr);
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54683006%2fget-key-value-pair-from-firebase-response-nested-json-object%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
5 Answers
5
active
oldest
votes
5 Answers
5
active
oldest
votes
active
oldest
votes
active
oldest
votes
It can be done using :
Using
Array.reduce
to accumulate thename
values into a single array.Using
Object.keys
andArray.map
to iterate through the keys and map it to thename
array.Using
Object.values
andArray.map
Using
Array.from
and utilizing the second mapping function parameter to map individual objects to an array ofnames
.
const obj = {"barID1":{"address":"4 East Terrace, Sydney NSW 2000","appStoreURL":"http://itunes.apple.com/app/idXXXXXXXXX","description":"description text","imgURLs":["Https:url1","https:url2","https:url3"],"lat":-34.810585,"lon":138.616739,"name":"Africola","phone":"(08) 8223 3885","status":"active","venueImgURL":"https:url"},"barID2":{"address":"138/140 Gouger St, Sydney NSW 2000","appStoreURL":"http://itunes.apple.com/app/idXXXXXXXXX","description":"description text","imgURLs":["Https:url1","https:url2","https:url3"],"lat":-34.848082,"lon":138.599813,"name":"Disco Mexico Taqueria","phone":"0416 855 108","status":"active","venueImgURL":"https:url"}};
//using Object.values & reduce
let name = Object.values(obj).reduce((acc, ele) =>{
return acc.concat(ele.name)
}, );
console.log(name);
//using Object.keys & map
name = Object.keys(obj).map((ele) => obj[ele]['name']);
console.log(name);
//using Object.values & map
name = Object.values(obj).map((ele) => ele.name);
console.log(name);
//using Array.from
name = Array.from(Object.values(obj), ele => ele.name);
console.log(name);
add a comment |
It can be done using :
Using
Array.reduce
to accumulate thename
values into a single array.Using
Object.keys
andArray.map
to iterate through the keys and map it to thename
array.Using
Object.values
andArray.map
Using
Array.from
and utilizing the second mapping function parameter to map individual objects to an array ofnames
.
const obj = {"barID1":{"address":"4 East Terrace, Sydney NSW 2000","appStoreURL":"http://itunes.apple.com/app/idXXXXXXXXX","description":"description text","imgURLs":["Https:url1","https:url2","https:url3"],"lat":-34.810585,"lon":138.616739,"name":"Africola","phone":"(08) 8223 3885","status":"active","venueImgURL":"https:url"},"barID2":{"address":"138/140 Gouger St, Sydney NSW 2000","appStoreURL":"http://itunes.apple.com/app/idXXXXXXXXX","description":"description text","imgURLs":["Https:url1","https:url2","https:url3"],"lat":-34.848082,"lon":138.599813,"name":"Disco Mexico Taqueria","phone":"0416 855 108","status":"active","venueImgURL":"https:url"}};
//using Object.values & reduce
let name = Object.values(obj).reduce((acc, ele) =>{
return acc.concat(ele.name)
}, );
console.log(name);
//using Object.keys & map
name = Object.keys(obj).map((ele) => obj[ele]['name']);
console.log(name);
//using Object.values & map
name = Object.values(obj).map((ele) => ele.name);
console.log(name);
//using Array.from
name = Array.from(Object.values(obj), ele => ele.name);
console.log(name);
add a comment |
It can be done using :
Using
Array.reduce
to accumulate thename
values into a single array.Using
Object.keys
andArray.map
to iterate through the keys and map it to thename
array.Using
Object.values
andArray.map
Using
Array.from
and utilizing the second mapping function parameter to map individual objects to an array ofnames
.
const obj = {"barID1":{"address":"4 East Terrace, Sydney NSW 2000","appStoreURL":"http://itunes.apple.com/app/idXXXXXXXXX","description":"description text","imgURLs":["Https:url1","https:url2","https:url3"],"lat":-34.810585,"lon":138.616739,"name":"Africola","phone":"(08) 8223 3885","status":"active","venueImgURL":"https:url"},"barID2":{"address":"138/140 Gouger St, Sydney NSW 2000","appStoreURL":"http://itunes.apple.com/app/idXXXXXXXXX","description":"description text","imgURLs":["Https:url1","https:url2","https:url3"],"lat":-34.848082,"lon":138.599813,"name":"Disco Mexico Taqueria","phone":"0416 855 108","status":"active","venueImgURL":"https:url"}};
//using Object.values & reduce
let name = Object.values(obj).reduce((acc, ele) =>{
return acc.concat(ele.name)
}, );
console.log(name);
//using Object.keys & map
name = Object.keys(obj).map((ele) => obj[ele]['name']);
console.log(name);
//using Object.values & map
name = Object.values(obj).map((ele) => ele.name);
console.log(name);
//using Array.from
name = Array.from(Object.values(obj), ele => ele.name);
console.log(name);
It can be done using :
Using
Array.reduce
to accumulate thename
values into a single array.Using
Object.keys
andArray.map
to iterate through the keys and map it to thename
array.Using
Object.values
andArray.map
Using
Array.from
and utilizing the second mapping function parameter to map individual objects to an array ofnames
.
const obj = {"barID1":{"address":"4 East Terrace, Sydney NSW 2000","appStoreURL":"http://itunes.apple.com/app/idXXXXXXXXX","description":"description text","imgURLs":["Https:url1","https:url2","https:url3"],"lat":-34.810585,"lon":138.616739,"name":"Africola","phone":"(08) 8223 3885","status":"active","venueImgURL":"https:url"},"barID2":{"address":"138/140 Gouger St, Sydney NSW 2000","appStoreURL":"http://itunes.apple.com/app/idXXXXXXXXX","description":"description text","imgURLs":["Https:url1","https:url2","https:url3"],"lat":-34.848082,"lon":138.599813,"name":"Disco Mexico Taqueria","phone":"0416 855 108","status":"active","venueImgURL":"https:url"}};
//using Object.values & reduce
let name = Object.values(obj).reduce((acc, ele) =>{
return acc.concat(ele.name)
}, );
console.log(name);
//using Object.keys & map
name = Object.keys(obj).map((ele) => obj[ele]['name']);
console.log(name);
//using Object.values & map
name = Object.values(obj).map((ele) => ele.name);
console.log(name);
//using Array.from
name = Array.from(Object.values(obj), ele => ele.name);
console.log(name);
const obj = {"barID1":{"address":"4 East Terrace, Sydney NSW 2000","appStoreURL":"http://itunes.apple.com/app/idXXXXXXXXX","description":"description text","imgURLs":["Https:url1","https:url2","https:url3"],"lat":-34.810585,"lon":138.616739,"name":"Africola","phone":"(08) 8223 3885","status":"active","venueImgURL":"https:url"},"barID2":{"address":"138/140 Gouger St, Sydney NSW 2000","appStoreURL":"http://itunes.apple.com/app/idXXXXXXXXX","description":"description text","imgURLs":["Https:url1","https:url2","https:url3"],"lat":-34.848082,"lon":138.599813,"name":"Disco Mexico Taqueria","phone":"0416 855 108","status":"active","venueImgURL":"https:url"}};
//using Object.values & reduce
let name = Object.values(obj).reduce((acc, ele) =>{
return acc.concat(ele.name)
}, );
console.log(name);
//using Object.keys & map
name = Object.keys(obj).map((ele) => obj[ele]['name']);
console.log(name);
//using Object.values & map
name = Object.values(obj).map((ele) => ele.name);
console.log(name);
//using Array.from
name = Array.from(Object.values(obj), ele => ele.name);
console.log(name);
const obj = {"barID1":{"address":"4 East Terrace, Sydney NSW 2000","appStoreURL":"http://itunes.apple.com/app/idXXXXXXXXX","description":"description text","imgURLs":["Https:url1","https:url2","https:url3"],"lat":-34.810585,"lon":138.616739,"name":"Africola","phone":"(08) 8223 3885","status":"active","venueImgURL":"https:url"},"barID2":{"address":"138/140 Gouger St, Sydney NSW 2000","appStoreURL":"http://itunes.apple.com/app/idXXXXXXXXX","description":"description text","imgURLs":["Https:url1","https:url2","https:url3"],"lat":-34.848082,"lon":138.599813,"name":"Disco Mexico Taqueria","phone":"0416 855 108","status":"active","venueImgURL":"https:url"}};
//using Object.values & reduce
let name = Object.values(obj).reduce((acc, ele) =>{
return acc.concat(ele.name)
}, );
console.log(name);
//using Object.keys & map
name = Object.keys(obj).map((ele) => obj[ele]['name']);
console.log(name);
//using Object.values & map
name = Object.values(obj).map((ele) => ele.name);
console.log(name);
//using Array.from
name = Array.from(Object.values(obj), ele => ele.name);
console.log(name);
edited 30 mins ago
answered 1 hour ago
Amardeep BhowmickAmardeep Bhowmick
2,94211123
2,94211123
add a comment |
add a comment |
You could extract the values of the input object via Object.values()
and then map()
the name
from each object
value as shown below to achieve this:
const data = {
barID1: {
address: "4 East Terrace, Sydney NSW 2000",
appStoreURL: "http://itunes.apple.com/app/idXXXXXXXXX",
description: "description text",
imgURLs: [ "Https:url1", "https:url2", "https:url3" ],
lat: -34.810585,
lon: 138.616739,
name: "Africola",
phone: "(08) 8223 3885",
status: "active",
venueImgURL: "https:url"
},
barID2: {
address: "138/140 Gouger St, Sydney NSW 2000",
appStoreURL: "http://itunes.apple.com/app/idXXXXXXXXX",
description: "description text",
imgURLs: [ "Https:url1", "https:url2", "https:url3" ],
lat: -34.848082,
lon: 138.599813,
name: "Disco Mexico Taqueria",
phone: "0416 855 108",
status: "active",
venueImgURL: "https:url"
}
}
console.log( Object.values(data).map(object => object.name) )
add a comment |
You could extract the values of the input object via Object.values()
and then map()
the name
from each object
value as shown below to achieve this:
const data = {
barID1: {
address: "4 East Terrace, Sydney NSW 2000",
appStoreURL: "http://itunes.apple.com/app/idXXXXXXXXX",
description: "description text",
imgURLs: [ "Https:url1", "https:url2", "https:url3" ],
lat: -34.810585,
lon: 138.616739,
name: "Africola",
phone: "(08) 8223 3885",
status: "active",
venueImgURL: "https:url"
},
barID2: {
address: "138/140 Gouger St, Sydney NSW 2000",
appStoreURL: "http://itunes.apple.com/app/idXXXXXXXXX",
description: "description text",
imgURLs: [ "Https:url1", "https:url2", "https:url3" ],
lat: -34.848082,
lon: 138.599813,
name: "Disco Mexico Taqueria",
phone: "0416 855 108",
status: "active",
venueImgURL: "https:url"
}
}
console.log( Object.values(data).map(object => object.name) )
add a comment |
You could extract the values of the input object via Object.values()
and then map()
the name
from each object
value as shown below to achieve this:
const data = {
barID1: {
address: "4 East Terrace, Sydney NSW 2000",
appStoreURL: "http://itunes.apple.com/app/idXXXXXXXXX",
description: "description text",
imgURLs: [ "Https:url1", "https:url2", "https:url3" ],
lat: -34.810585,
lon: 138.616739,
name: "Africola",
phone: "(08) 8223 3885",
status: "active",
venueImgURL: "https:url"
},
barID2: {
address: "138/140 Gouger St, Sydney NSW 2000",
appStoreURL: "http://itunes.apple.com/app/idXXXXXXXXX",
description: "description text",
imgURLs: [ "Https:url1", "https:url2", "https:url3" ],
lat: -34.848082,
lon: 138.599813,
name: "Disco Mexico Taqueria",
phone: "0416 855 108",
status: "active",
venueImgURL: "https:url"
}
}
console.log( Object.values(data).map(object => object.name) )
You could extract the values of the input object via Object.values()
and then map()
the name
from each object
value as shown below to achieve this:
const data = {
barID1: {
address: "4 East Terrace, Sydney NSW 2000",
appStoreURL: "http://itunes.apple.com/app/idXXXXXXXXX",
description: "description text",
imgURLs: [ "Https:url1", "https:url2", "https:url3" ],
lat: -34.810585,
lon: 138.616739,
name: "Africola",
phone: "(08) 8223 3885",
status: "active",
venueImgURL: "https:url"
},
barID2: {
address: "138/140 Gouger St, Sydney NSW 2000",
appStoreURL: "http://itunes.apple.com/app/idXXXXXXXXX",
description: "description text",
imgURLs: [ "Https:url1", "https:url2", "https:url3" ],
lat: -34.848082,
lon: 138.599813,
name: "Disco Mexico Taqueria",
phone: "0416 855 108",
status: "active",
venueImgURL: "https:url"
}
}
console.log( Object.values(data).map(object => object.name) )
const data = {
barID1: {
address: "4 East Terrace, Sydney NSW 2000",
appStoreURL: "http://itunes.apple.com/app/idXXXXXXXXX",
description: "description text",
imgURLs: [ "Https:url1", "https:url2", "https:url3" ],
lat: -34.810585,
lon: 138.616739,
name: "Africola",
phone: "(08) 8223 3885",
status: "active",
venueImgURL: "https:url"
},
barID2: {
address: "138/140 Gouger St, Sydney NSW 2000",
appStoreURL: "http://itunes.apple.com/app/idXXXXXXXXX",
description: "description text",
imgURLs: [ "Https:url1", "https:url2", "https:url3" ],
lat: -34.848082,
lon: 138.599813,
name: "Disco Mexico Taqueria",
phone: "0416 855 108",
status: "active",
venueImgURL: "https:url"
}
}
console.log( Object.values(data).map(object => object.name) )
const data = {
barID1: {
address: "4 East Terrace, Sydney NSW 2000",
appStoreURL: "http://itunes.apple.com/app/idXXXXXXXXX",
description: "description text",
imgURLs: [ "Https:url1", "https:url2", "https:url3" ],
lat: -34.810585,
lon: 138.616739,
name: "Africola",
phone: "(08) 8223 3885",
status: "active",
venueImgURL: "https:url"
},
barID2: {
address: "138/140 Gouger St, Sydney NSW 2000",
appStoreURL: "http://itunes.apple.com/app/idXXXXXXXXX",
description: "description text",
imgURLs: [ "Https:url1", "https:url2", "https:url3" ],
lat: -34.848082,
lon: 138.599813,
name: "Disco Mexico Taqueria",
phone: "0416 855 108",
status: "active",
venueImgURL: "https:url"
}
}
console.log( Object.values(data).map(object => object.name) )
answered 1 hour ago
Dacre DennyDacre Denny
12.2k41031
12.2k41031
add a comment |
add a comment |
Here I use for in
to loop each object in your JSON then push the name into the result array.
const data = {
"barID1": {
"address": "4 East Terrace, Sydney NSW 2000",
"appStoreURL": "http://itunes.apple.com/app/idXXXXXXXXX",
"description": "description text",
"imgURLs": ["Https:url1", "https: url2", "https:url3"],
"lat": -34.810585,
"lon": 138.616739,
"name": "Africola",
"phone": "(08) 8223 3885",
"status": "active",
"venueImgURL": "https:url"
},
"barID2": {
"address": "138/140 Gouger St, Sydney NSW 2000",
"appStoreURL": "http://itunes.apple.com/app/idXXXXXXXXX",
"description": "description text",
"imgURLs": ["Https:url1", "https: url2", "https:url3"],
"lat": -34.848082,
"lon": 138.599813,
"name": "Disco Mexico Taqueria",
"phone": "0416 855 108",
"status": "active",
"venueImgURL": "https:url"
}
}
let result =
for (let i in data) {
result.push(data[i].name)
}
console.log(result)
add a comment |
Here I use for in
to loop each object in your JSON then push the name into the result array.
const data = {
"barID1": {
"address": "4 East Terrace, Sydney NSW 2000",
"appStoreURL": "http://itunes.apple.com/app/idXXXXXXXXX",
"description": "description text",
"imgURLs": ["Https:url1", "https: url2", "https:url3"],
"lat": -34.810585,
"lon": 138.616739,
"name": "Africola",
"phone": "(08) 8223 3885",
"status": "active",
"venueImgURL": "https:url"
},
"barID2": {
"address": "138/140 Gouger St, Sydney NSW 2000",
"appStoreURL": "http://itunes.apple.com/app/idXXXXXXXXX",
"description": "description text",
"imgURLs": ["Https:url1", "https: url2", "https:url3"],
"lat": -34.848082,
"lon": 138.599813,
"name": "Disco Mexico Taqueria",
"phone": "0416 855 108",
"status": "active",
"venueImgURL": "https:url"
}
}
let result =
for (let i in data) {
result.push(data[i].name)
}
console.log(result)
add a comment |
Here I use for in
to loop each object in your JSON then push the name into the result array.
const data = {
"barID1": {
"address": "4 East Terrace, Sydney NSW 2000",
"appStoreURL": "http://itunes.apple.com/app/idXXXXXXXXX",
"description": "description text",
"imgURLs": ["Https:url1", "https: url2", "https:url3"],
"lat": -34.810585,
"lon": 138.616739,
"name": "Africola",
"phone": "(08) 8223 3885",
"status": "active",
"venueImgURL": "https:url"
},
"barID2": {
"address": "138/140 Gouger St, Sydney NSW 2000",
"appStoreURL": "http://itunes.apple.com/app/idXXXXXXXXX",
"description": "description text",
"imgURLs": ["Https:url1", "https: url2", "https:url3"],
"lat": -34.848082,
"lon": 138.599813,
"name": "Disco Mexico Taqueria",
"phone": "0416 855 108",
"status": "active",
"venueImgURL": "https:url"
}
}
let result =
for (let i in data) {
result.push(data[i].name)
}
console.log(result)
Here I use for in
to loop each object in your JSON then push the name into the result array.
const data = {
"barID1": {
"address": "4 East Terrace, Sydney NSW 2000",
"appStoreURL": "http://itunes.apple.com/app/idXXXXXXXXX",
"description": "description text",
"imgURLs": ["Https:url1", "https: url2", "https:url3"],
"lat": -34.810585,
"lon": 138.616739,
"name": "Africola",
"phone": "(08) 8223 3885",
"status": "active",
"venueImgURL": "https:url"
},
"barID2": {
"address": "138/140 Gouger St, Sydney NSW 2000",
"appStoreURL": "http://itunes.apple.com/app/idXXXXXXXXX",
"description": "description text",
"imgURLs": ["Https:url1", "https: url2", "https:url3"],
"lat": -34.848082,
"lon": 138.599813,
"name": "Disco Mexico Taqueria",
"phone": "0416 855 108",
"status": "active",
"venueImgURL": "https:url"
}
}
let result =
for (let i in data) {
result.push(data[i].name)
}
console.log(result)
const data = {
"barID1": {
"address": "4 East Terrace, Sydney NSW 2000",
"appStoreURL": "http://itunes.apple.com/app/idXXXXXXXXX",
"description": "description text",
"imgURLs": ["Https:url1", "https: url2", "https:url3"],
"lat": -34.810585,
"lon": 138.616739,
"name": "Africola",
"phone": "(08) 8223 3885",
"status": "active",
"venueImgURL": "https:url"
},
"barID2": {
"address": "138/140 Gouger St, Sydney NSW 2000",
"appStoreURL": "http://itunes.apple.com/app/idXXXXXXXXX",
"description": "description text",
"imgURLs": ["Https:url1", "https: url2", "https:url3"],
"lat": -34.848082,
"lon": 138.599813,
"name": "Disco Mexico Taqueria",
"phone": "0416 855 108",
"status": "active",
"venueImgURL": "https:url"
}
}
let result =
for (let i in data) {
result.push(data[i].name)
}
console.log(result)
const data = {
"barID1": {
"address": "4 East Terrace, Sydney NSW 2000",
"appStoreURL": "http://itunes.apple.com/app/idXXXXXXXXX",
"description": "description text",
"imgURLs": ["Https:url1", "https: url2", "https:url3"],
"lat": -34.810585,
"lon": 138.616739,
"name": "Africola",
"phone": "(08) 8223 3885",
"status": "active",
"venueImgURL": "https:url"
},
"barID2": {
"address": "138/140 Gouger St, Sydney NSW 2000",
"appStoreURL": "http://itunes.apple.com/app/idXXXXXXXXX",
"description": "description text",
"imgURLs": ["Https:url1", "https: url2", "https:url3"],
"lat": -34.848082,
"lon": 138.599813,
"name": "Disco Mexico Taqueria",
"phone": "0416 855 108",
"status": "active",
"venueImgURL": "https:url"
}
}
let result =
for (let i in data) {
result.push(data[i].name)
}
console.log(result)
answered 1 hour ago
holydragonholydragon
1,8152924
1,8152924
add a comment |
add a comment |
You can map() the Object.values() of the json structure.
const json = {
"barID1": {
"address": "4 East Terrace, Sydney NSW 2000",
"appStoreURL": "http://itunes.apple.com/app/idXXXXXXXXX",
"description": "description text",
"imgURLs": [ "Https:url1", "https:url2", "https:url3" ],
"lat": -34.810585,
"lon": 138.616739,
"name": "Africola",
"phone": "(08) 8223 3885",
"status": "active",
"venueImgURL": "https:url"
},
"barID2": {
"address": "138/140 Gouger St, Sydney NSW 2000",
"appStoreURL": "http://itunes.apple.com/app/idXXXXXXXXX",
"description": "description text",
"imgURLs": [ "Https:url1", "https:url2", "https:url3" ],
"lat": -34.848082,
"lon": 138.599813,
"name": "Disco Mexico Taqueria",
"phone": "0416 855 108",
"status": "active",
"venueImgURL": "https:url"
}
};
let res = Object.values(json).map(({name}) => name);
console.log(res);
add a comment |
You can map() the Object.values() of the json structure.
const json = {
"barID1": {
"address": "4 East Terrace, Sydney NSW 2000",
"appStoreURL": "http://itunes.apple.com/app/idXXXXXXXXX",
"description": "description text",
"imgURLs": [ "Https:url1", "https:url2", "https:url3" ],
"lat": -34.810585,
"lon": 138.616739,
"name": "Africola",
"phone": "(08) 8223 3885",
"status": "active",
"venueImgURL": "https:url"
},
"barID2": {
"address": "138/140 Gouger St, Sydney NSW 2000",
"appStoreURL": "http://itunes.apple.com/app/idXXXXXXXXX",
"description": "description text",
"imgURLs": [ "Https:url1", "https:url2", "https:url3" ],
"lat": -34.848082,
"lon": 138.599813,
"name": "Disco Mexico Taqueria",
"phone": "0416 855 108",
"status": "active",
"venueImgURL": "https:url"
}
};
let res = Object.values(json).map(({name}) => name);
console.log(res);
add a comment |
You can map() the Object.values() of the json structure.
const json = {
"barID1": {
"address": "4 East Terrace, Sydney NSW 2000",
"appStoreURL": "http://itunes.apple.com/app/idXXXXXXXXX",
"description": "description text",
"imgURLs": [ "Https:url1", "https:url2", "https:url3" ],
"lat": -34.810585,
"lon": 138.616739,
"name": "Africola",
"phone": "(08) 8223 3885",
"status": "active",
"venueImgURL": "https:url"
},
"barID2": {
"address": "138/140 Gouger St, Sydney NSW 2000",
"appStoreURL": "http://itunes.apple.com/app/idXXXXXXXXX",
"description": "description text",
"imgURLs": [ "Https:url1", "https:url2", "https:url3" ],
"lat": -34.848082,
"lon": 138.599813,
"name": "Disco Mexico Taqueria",
"phone": "0416 855 108",
"status": "active",
"venueImgURL": "https:url"
}
};
let res = Object.values(json).map(({name}) => name);
console.log(res);
You can map() the Object.values() of the json structure.
const json = {
"barID1": {
"address": "4 East Terrace, Sydney NSW 2000",
"appStoreURL": "http://itunes.apple.com/app/idXXXXXXXXX",
"description": "description text",
"imgURLs": [ "Https:url1", "https:url2", "https:url3" ],
"lat": -34.810585,
"lon": 138.616739,
"name": "Africola",
"phone": "(08) 8223 3885",
"status": "active",
"venueImgURL": "https:url"
},
"barID2": {
"address": "138/140 Gouger St, Sydney NSW 2000",
"appStoreURL": "http://itunes.apple.com/app/idXXXXXXXXX",
"description": "description text",
"imgURLs": [ "Https:url1", "https:url2", "https:url3" ],
"lat": -34.848082,
"lon": 138.599813,
"name": "Disco Mexico Taqueria",
"phone": "0416 855 108",
"status": "active",
"venueImgURL": "https:url"
}
};
let res = Object.values(json).map(({name}) => name);
console.log(res);
const json = {
"barID1": {
"address": "4 East Terrace, Sydney NSW 2000",
"appStoreURL": "http://itunes.apple.com/app/idXXXXXXXXX",
"description": "description text",
"imgURLs": [ "Https:url1", "https:url2", "https:url3" ],
"lat": -34.810585,
"lon": 138.616739,
"name": "Africola",
"phone": "(08) 8223 3885",
"status": "active",
"venueImgURL": "https:url"
},
"barID2": {
"address": "138/140 Gouger St, Sydney NSW 2000",
"appStoreURL": "http://itunes.apple.com/app/idXXXXXXXXX",
"description": "description text",
"imgURLs": [ "Https:url1", "https:url2", "https:url3" ],
"lat": -34.848082,
"lon": 138.599813,
"name": "Disco Mexico Taqueria",
"phone": "0416 855 108",
"status": "active",
"venueImgURL": "https:url"
}
};
let res = Object.values(json).map(({name}) => name);
console.log(res);
const json = {
"barID1": {
"address": "4 East Terrace, Sydney NSW 2000",
"appStoreURL": "http://itunes.apple.com/app/idXXXXXXXXX",
"description": "description text",
"imgURLs": [ "Https:url1", "https:url2", "https:url3" ],
"lat": -34.810585,
"lon": 138.616739,
"name": "Africola",
"phone": "(08) 8223 3885",
"status": "active",
"venueImgURL": "https:url"
},
"barID2": {
"address": "138/140 Gouger St, Sydney NSW 2000",
"appStoreURL": "http://itunes.apple.com/app/idXXXXXXXXX",
"description": "description text",
"imgURLs": [ "Https:url1", "https:url2", "https:url3" ],
"lat": -34.848082,
"lon": 138.599813,
"name": "Disco Mexico Taqueria",
"phone": "0416 855 108",
"status": "active",
"venueImgURL": "https:url"
}
};
let res = Object.values(json).map(({name}) => name);
console.log(res);
answered 1 hour ago
ShiderszShidersz
7,0172831
7,0172831
add a comment |
add a comment |
The simplest solution is Object.values
:
const data = {"barID1":{"address":"4 East Terrace, Sydney NSW 2000","appStoreURL":"http://itunes.apple.com/app/idXXXXXXXXX","description":"description text","imgURLs":["Https:url1","https:url2","https:url3"],"lat":-34.810585,"lon":138.616739,"name":"Africola","phone":"(08) 8223 3885","status":"active","venueImgURL":"https:url"},"barID2":{"address":"138/140 Gouger St, Sydney NSW 2000","appStoreURL":"http://itunes.apple.com/app/idXXXXXXXXX","description":"description text","imgURLs":["Https:url1","https:url2","https:url3"],"lat":-34.848082,"lon":138.599813,"name":"Disco Mexico Taqueria","phone":"0416 855 108","status":"active","venueImgURL":"https:url"}};
const namesArr = Object.values(data).map(({ name }) => name);
console.log(namesArr);
add a comment |
The simplest solution is Object.values
:
const data = {"barID1":{"address":"4 East Terrace, Sydney NSW 2000","appStoreURL":"http://itunes.apple.com/app/idXXXXXXXXX","description":"description text","imgURLs":["Https:url1","https:url2","https:url3"],"lat":-34.810585,"lon":138.616739,"name":"Africola","phone":"(08) 8223 3885","status":"active","venueImgURL":"https:url"},"barID2":{"address":"138/140 Gouger St, Sydney NSW 2000","appStoreURL":"http://itunes.apple.com/app/idXXXXXXXXX","description":"description text","imgURLs":["Https:url1","https:url2","https:url3"],"lat":-34.848082,"lon":138.599813,"name":"Disco Mexico Taqueria","phone":"0416 855 108","status":"active","venueImgURL":"https:url"}};
const namesArr = Object.values(data).map(({ name }) => name);
console.log(namesArr);
add a comment |
The simplest solution is Object.values
:
const data = {"barID1":{"address":"4 East Terrace, Sydney NSW 2000","appStoreURL":"http://itunes.apple.com/app/idXXXXXXXXX","description":"description text","imgURLs":["Https:url1","https:url2","https:url3"],"lat":-34.810585,"lon":138.616739,"name":"Africola","phone":"(08) 8223 3885","status":"active","venueImgURL":"https:url"},"barID2":{"address":"138/140 Gouger St, Sydney NSW 2000","appStoreURL":"http://itunes.apple.com/app/idXXXXXXXXX","description":"description text","imgURLs":["Https:url1","https:url2","https:url3"],"lat":-34.848082,"lon":138.599813,"name":"Disco Mexico Taqueria","phone":"0416 855 108","status":"active","venueImgURL":"https:url"}};
const namesArr = Object.values(data).map(({ name }) => name);
console.log(namesArr);
The simplest solution is Object.values
:
const data = {"barID1":{"address":"4 East Terrace, Sydney NSW 2000","appStoreURL":"http://itunes.apple.com/app/idXXXXXXXXX","description":"description text","imgURLs":["Https:url1","https:url2","https:url3"],"lat":-34.810585,"lon":138.616739,"name":"Africola","phone":"(08) 8223 3885","status":"active","venueImgURL":"https:url"},"barID2":{"address":"138/140 Gouger St, Sydney NSW 2000","appStoreURL":"http://itunes.apple.com/app/idXXXXXXXXX","description":"description text","imgURLs":["Https:url1","https:url2","https:url3"],"lat":-34.848082,"lon":138.599813,"name":"Disco Mexico Taqueria","phone":"0416 855 108","status":"active","venueImgURL":"https:url"}};
const namesArr = Object.values(data).map(({ name }) => name);
console.log(namesArr);
const data = {"barID1":{"address":"4 East Terrace, Sydney NSW 2000","appStoreURL":"http://itunes.apple.com/app/idXXXXXXXXX","description":"description text","imgURLs":["Https:url1","https:url2","https:url3"],"lat":-34.810585,"lon":138.616739,"name":"Africola","phone":"(08) 8223 3885","status":"active","venueImgURL":"https:url"},"barID2":{"address":"138/140 Gouger St, Sydney NSW 2000","appStoreURL":"http://itunes.apple.com/app/idXXXXXXXXX","description":"description text","imgURLs":["Https:url1","https:url2","https:url3"],"lat":-34.848082,"lon":138.599813,"name":"Disco Mexico Taqueria","phone":"0416 855 108","status":"active","venueImgURL":"https:url"}};
const namesArr = Object.values(data).map(({ name }) => name);
console.log(namesArr);
const data = {"barID1":{"address":"4 East Terrace, Sydney NSW 2000","appStoreURL":"http://itunes.apple.com/app/idXXXXXXXXX","description":"description text","imgURLs":["Https:url1","https:url2","https:url3"],"lat":-34.810585,"lon":138.616739,"name":"Africola","phone":"(08) 8223 3885","status":"active","venueImgURL":"https:url"},"barID2":{"address":"138/140 Gouger St, Sydney NSW 2000","appStoreURL":"http://itunes.apple.com/app/idXXXXXXXXX","description":"description text","imgURLs":["Https:url1","https:url2","https:url3"],"lat":-34.848082,"lon":138.599813,"name":"Disco Mexico Taqueria","phone":"0416 855 108","status":"active","venueImgURL":"https:url"}};
const namesArr = Object.values(data).map(({ name }) => name);
console.log(namesArr);
answered 59 mins ago
Jack BashfordJack Bashford
8,53131539
8,53131539
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54683006%2fget-key-value-pair-from-firebase-response-nested-json-object%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown