Get object from an array inside of an array - javascript

I am trying to get a list of places from Foursquare's API. So far so good, but I have hit a wall that I can't figure out. Hopefully someone on here might have a good idea.
The list I currently have shows the types of venues from a forsquare list, and then it breaks down each venue's name and lat/lng. The issue that I am having is getting the category from foursquare. The category is stored inside of another array, inside of the array for the venue.
Here is what I have so far:
function app(info) {
$('#content').append(info);
}
function getinfo(venueAPI) {
$.getJSON(venueAPI, function (data) {
var arr = [];
var venuearr = [];
$('#content').empty();
console.log(data);
b = '<br/>';
categoryArr = data.response.list.categories.items;
categoryArrLength = data.response.list.categories.items.length;
console.log(categoryArr);
console.log(categoryArrLength);
for (var x = 0; x < categoryArrLength; x++) {
app(categoryArr[x].category.pluralName + b);
}
arr = data.response.list.listItems;
venuearr = arr.items;
console.log(venuearr);
for (var i = 0; i < venuearr.length; i++) {
ltlng = L.latLng(venuearr[i].venue.location.lat, venuearr[i].venue.location.lng);
$('#content').append(ltlng + b);
app(venuearr[i].venue.name + b);
}
});
getinfo();
}
which returns JSON like this for each venue:
"venue": {
"id": "51db2eca498e76d75a5dfea2",
"name": "A Gathering Of Stitches",
"contact": {},
"location": {
"address": "54 Cove St",
"lat": 43.66797,
"lng": -70.256453,
"cc": "US",
"city": "Portland",
"state": "ME",
"country": "United States",
"formattedAddress": [
"54 Cove St",
"Portland, ME"
]
},
"categories": [
{
"id": "4bf58dd8d48988d1f4941735",
"name": "Design Studio",
"pluralName": "Design Studios",
"shortName": "Design",
"icon": {
"prefix": "https://ss3.4sqi.net/img/categories_v2/shops/design_",
"suffix": ".png"
},
"primary": true
}
],
and this is what get's printed out on the screen:
Pubs
Thrift / Vintage Stores
Design Studios
Coffee Shops
LatLng(43.6565, -70.25313)
Bull Feeney's
LatLng(43.65697, -70.25081)
Andy's Old Port Pub
LatLng(43.6571, -70.25713)
Arabica Coffee
LatLng(43.66797, -70.25645)
A Gathering Of Stitches
LatLng(43.65687, -70.25763)
Find
I've tried several different ideas, but nothing has seemed to work so far.

venue.categories[0].name;
fiddle:
http://jsfiddle.net/18kfrek5/

Related

Employees in companies - displaying JSON data in html table

I have json data like this :
{
"people": [
{
"id": "1",
"company": "Blitz",
"fullName": "Chad anderson"
},
{
"id": "2",
"company": "NFZ",
"fullName": "surge bash"
},
{
"id": "3",
"company": "Ultimate Chad Company LLC",
"fullName": "George"
},
{
"id": "4",
"company": "Blitz",
"fullName": "Chad kuton"
},
{
"id": "5",
"company": "NFZ",
"fullName": "piguĊ‚a"
},
]);
currently I have code like this:
function appendData(data) {
let tblBody = document.getElementById('tableWithContent');
let outPut = '';
data.sort((a,b) => a.company.localeCompare(b.company));
for(let person of data){
outPut += `<tr>
<td></td>
<td>${person.fullName}</td>
<td>${person.company}</td>
</tr>`;
}
tblBody.innerHTML = outPut;
};
I would like to display it in a way that :
Creates html table populated with companies and names of employess, within that company. In a way that if both workers have the same company , they are just displayed within that one company.
However, the code displays , and it displays workers in one column, and companies in another.
I would like to know if there is a neat way to use for example. reduce() method to that.
So when I fetch this data to html it displays all of the people from one company , then all of the people from another company (without displaying the companies of employees each time - if they are from the same company).

how to print ipdata language name using javascript?

Hi guys I need to know how to print the language name in ipdata
I have this code at the bottom working well and the results appear correct but when I get the name of the language the results show the language name = undefined;
results
184.23.215.250
United States
<img src="https://ipdata.co/flags/us.png">
US
North America
Sonic Telecom LLC
undefined
my js vars is
var country_name = response.country_name;
var flag = response.flag;
var country_code = response.country_code;
var continent_name = response.continent_name;
var organisation = response.organisation;
var lang = response.languages.name;
you can try it from http://tiger222.atwebpages.com/set.php
You will find the data correct but, how do I get the language name correctly ?
var lang = response.languages->name; this is not working
var lang = response.languages.name; and this is not working
In the source data, languages is an array, e.g.
"languages": [
{
"name": "English",
"native": "English"
}
],
Therefore it can potentially contain multiple entries.
Assuming you just want the first language in the list, then you can address the first index of the array directly, like this:
var lang = response.languages[0].name;
P.S. -> is not valid syntax in JavaScript. You were perhaps thinking of PHP syntax there.
This is array
var lang = response.languages[0].name;
Languages is an array so you would have to map on its elements and get name out of it.
"languages": [
{
"name": "English",
"native": "English"
}
],
It may break if there are no languages in the array so you can do defensive code like below:
var lang = (response.languages && response.languages.length && response.languages[0].name) || '';
const response = {
"ip": "12.00.00.01",
"is_eu": false,
"city": "Any City",
"region": "Pennsylvania",
"region_code": "PA",
"country_name": "United States",
"country_code": "US",
"continent_name": "North America",
"continent_code": "NA",
"latitude": 49.9776,
"longitude": -95.3099,
"asn": "AS7018",
"organisation": "AT&T Services, Inc.",
"postal": "18083",
"calling_code": "1",
"flag": "https://ipdata.co/flags/us.png",
"emoji_flag": "\ud83c\uddfa\ud83c\uddf8",
"emoji_unicode": "U+1F1FA U+1F1F8",
"carrier": {
"name": "AT&T",
"mcc": "310",
"mnc": "016"
},
"languages": [
{
"name": "English",
"native": "English"
}
],
"currency": {
"name": "US Dollar",
"code": "USD",
"symbol": "$",
"native": "$",
"plural": "US dollars"
},
"time_zone": {
"name": "America/New_York",
"abbr": "EDT",
"offset": "-0400",
"is_dst": true,
"current_time": "2019-05-30T08:52:43.569643-04:00"
},
"threat": {
"is_tor": false,
"is_proxy": false,
"is_anonymous": false,
"is_known_attacker": false,
"is_known_abuser": false,
"is_threat": false,
"is_bogon": false
},
"count": "1501"
};
var country_name = response.country_name;
var flag = response.flag;
var country_code = response.country_code;
var continent_name = response.continent_name;
var organisation = response.organisation;
var lang = response.languages[0].name;
console.log(lang);

How to replace object value based on hash table (ex. "State": "CO" changes to "State": "Colorado")

Simplified Version of Problem:
I have an object that looks like this:
var info = [{
"population": 1234,
"state": "AL"
},{
"population": 1234,
"state": "AK"
}]
I need to replace the state two letter abbreviation with the actual state name. I have this available as follows:
var stateNames = {
"AL": "Alabama",
"AK": "Alaska"
};
The goal is to have it result in this:
[{
"population": 1234,
"state": "Alabama"
},{
"population": 1234,
"state": "Alaska"
}]
I have circled this long enough that I am pretty confused. My instructions to myself go like this:
Check every info.state value to see if it matches a key within stateNames.
If it matches, replace the info.state value with that stateNames value.
If there is no match, leave it.
Return object.
Some Possibly Related Code:
I have been searching SO for possible solutions and despite putting a good bit of time, don't have too much to offer. I do think using a foreach is probably right, and I think this SO question/answer is in the right direction:
Object.keys(hashmap).forEach(function(key) {
var newkey = key + "xxx";
hashmap[newkey] = hashmap[key];
delete hashmap[key];
});
But I haven't been able to successfully adapt it. Any help or advice is very appreciated - thanks for reading!
A JS Bin:
http://jsbin.com/nojamoyeya/2/edit?js,console
You can resolve a state's full name by using its short name as the key in stateNames. Basically: stateNames[shortName] = longName. You can use Object.prototype.hasOwnProperty to check if stateNames contains a specific key. Here is one way to do it:
var info = [{
"population": 1234,
"state": "AL"
},{
"population": 1234,
"state": "AK"
}];
var stateNames = {
"AL": "Alabama",
"AK": "Alaska"
};
info.forEach(function(state) {
if(stateNames.hasOwnProperty(state.state)) {
state.state = stateNames[state.state];
}
});
info.forEach(function (item) {
if (stateName[item.state]) {
item.state = stateName[item.state];
}
}
Would be one way.
var info = [{
"population": 1234,
"state": "AL"
}, {
"population": 1234,
"state": "AK"
}];
var stateNames = {
"AL": "Alabama",
"AK": "Alaska"
};
info.forEach(function (inf) {
if(inf.state in stateNames){
inf.state = stateNames[inf.state];
}
});
console.log(info);
updated js bin is here
http://jsbin.com/julexovete/1/edit?js,console
// Code
for(var i =0; i < info.length; i++){
if(stateNames[info[i]["state"]]){
info[i]["state"] = stateNames[info[i]["state"]];
}
}

Trying to filter and combine JSON items

I have a JSON with several objects with this format:
[{
"id":14,
"friendlyName":"NameOfPlace 1",
"lat":30.402735,
"lon":-90,
"address":"1 place street",
"city":"NYC",
"state":"NY",
"zipCode":"12346",
"locationCode":"MQ00003",
"details":"in the bank"
},
{
"id":15,
"friendlyName":"NameOfPlace 2",
"lat":30.402735,
"lon":-90,
"address":"1 place street",
"city":"NYC",
"state":"NY",
"zipCode":"12346",
"locationCode":"MQ00003",
"details":"near ATM"
}]
They are locations of stores. I have several of these in a list. Some of them have names like Name 1 and Name 2, if there are 2 locations within the same building. I am trying to find a way to combine them into one object with both values but only one place ("Name" in the case of the example). I have two questions, if I have list of objects like above can I sort based off of friendlyName alphabetically then check to see if there are similar named locations that can be combined into one object. Note the locations will have the same lat long and address, just different details and ids. I can only figure out how todo it linearly and it is very slow for the mobile app I am trying to do.
You could use a hash table for the grouping of the friendly name and generate a new array with the data. If the data is different, all values are in an array included.
var data = [{ "id": 14, "friendlyName": "NameOfPlace 1", "lat": 30.402735, "lon": -90, "address": "1 place street", "city": "NYC", "state": "NY", "zipCode": "12346", "locationCode": "MQ00003", "details": "in the bank" }, { "id": 15, "friendlyName": "NameOfPlace 2", "lat": 30.402735, "lon": -90, "address": "1 place street", "city": "NYC", "state": "NY", "zipCode": "12346", "locationCode": "MQ00003", "details": "near ATM" }],
grouped = [];
data.forEach(function (o) {
var key = o.friendlyName.split(/(?= \d*$)/)[0];
if (!this[key]) {
this[key] = { Name: key };
grouped.push(this[key]);
}
Object.keys(o).forEach(function (k) {
if (!(k in this[key])) {
this[key][k] = o[k];
return;
}
if (this[key][k] === o[k]) {
return true;
}
if (Array.isArray(this[key][k])) {
this[key][k].push(o[k]);
return;
}
this[key][k] = [this[key][k], o[k]];
}, this);
}, Object.create(null));
console.log(grouped);
can I sort based off of friendlyName alphabetically
You can do it by using sort method
var sortedArray = json.sort(function(a,b){
return a.friendlyName>b.friendlyName?1:-1
})
JSFIDDLE

Having trouble using data retrieved with json in javascript, cannot sort the array

I am trying to sort out the data I retrieved from an api with javascript.
Code :
function getResults() {
var url = $.getJSON("http://api.api.com&leagues=SOCENGPRE&lang=en&format=jsonp&callback=?", function(jsondata){;
for(var i = 0; i < jsondata.length; i++)
for(var id in jsondata[i]) {
console.log("ID - " + id);
console.log("TEAM - " + jsondata[i][id].home_team);
}
});
}
Example of data retrieved :
{
"SOCENGPRE": {
"league_name": "Barclays Premier League",
"league_phid": null,
"league_type": null,
"fixtures": [
{
"id": "64714",
"code": "SOCENGPRE",
"event_slug": "west_ham-tottenham-1401290",
"home_team": "West Ham",
"away_team": "Tottenham",
},
{
"id": "64711",
"code": "SOCENGPRE",
"event_slug": "manchester_u-sunderland-1401286",
"home_team": "Manchester U",
"away_team": "Sunderland"
}
But using my code I cannot seem to get the results I am wanting.
I want to print out every games ID and Home Team. Any insights on why is my code not working? Thank you very much in advance!
UPDATE: I have removed the extra semi-colon but it's still not printing the data for me.
UPDATE 2: Regarding the requests for the URL. When I call it in a browser I get this huge result
?({"SOCENGPRE":{"league_name":"Barclays Premier League","league_phid":null,"league_type":null,"fixtures":[{"id":"64714","code":"SOCENGPRE","event_slug":"west_ham-tottenham-1401290","start":"1399117500","home_team":"West Ham","home_team_phid":null,"home_team_logo":"\/\/dxnxhx88pdxyv.cloudfront.net\/logo\/32\/t523.png","home_team_short":"","away_team":"Tottenham","away_team_phid":null,"away_team_logo":"\/\/dxnxhx88pdxyv.cloudfront.net\/logo\/32\/t498.png","away_team_short":"","phid":null},{"id":"64711","code":"SOCENGPRE","event_slug":"manchester_u-sunderland-1401286","start":"1399125600","home_team":"Manchester U","home_team_phid":null,"home_team_logo":"\/\/dxnxhx88pdxyv.cloudfront.net\/logo\/32\/t20790.png","home_team_short":"Man U","away_team":"Sunderland","away_team_phid":null,"away_team_logo":"\/\/dxnxhx88pdxyv.cloudfront.net\/logo\/32\/t382.png","away_team_short":"","phid":null},{"id":"64712","code":"SOCENGPRE","event_slug":"stoke-fulham-1401288","start":"1399125600","home_team":"Stoke","home_team_phid":null,"home_team_logo":"\/\/dxnxhx88pdxyv.cloudfront.net\/logo\/32\/t389.png","home_team_short":"","away_team":"Fulham","away_team_phid":null,"away_team_logo":"\/\/dxnxhx88pdxyv.cloudfront.net\/logo\/32\/t379.png","away_team_short":"","phid":null},{"id":"64706","code":"SOCENGPRE","event_slug":"aston_villa-hull-1401282","start":"1399125600","home_team":"Aston Villa","home_team_phid":null,"home_team_logo":"\/\/dxnxhx88pdxyv.cloudfront.net\/logo\/32\/t380.png","home_team_short":"","away_team":"Hull","away_team_phid":null,"away_team_logo":"\/\/dxnxhx88pdxyv.cloudfront.net\/logo\/32\/t511.png","away_team_short":"Hull","phid":null},{"id":"64710","code":"SOCENGPRE","event_slug":"newcastle-cardiff-1401287","start":"1399125600","home_team":"Newcastle","home_team_phid":null,"home_team_logo":"\/\/dxnxhx88pdxyv.cloudfront.net\/logo\/32\/t385.png","home_team_short":"","away_team":"Cardiff","away_team_phid":null,"away_team_logo":"\/\/dxnxhx88pdxyv.cloudfront.net\/logo\/32\/t524.png","away_team_short":"","phid":null},{"id":"64713","code":"SOCENGPRE","event_slug":"swansea-southampton-1401289","start":"1399125600","home_team":"Swansea","home_team_phid":null,"home_team_logo":"\/\/dxnxhx88pdxyv.cloudfront.net\/logo\/32\/t384.png","home_team_short":"Swansea","away_team":"Southampton","away_team_phid":null,"away_team_logo":"\/\/dxnxhx88pdxyv.cloudfront.net\/logo\/32\/t8482.png","away_team_short":"","phid":null},{"id":"64709","code":"SOCENGPRE","event_slug":"everton-manchester_c-1401285","start":"1399134600","home_team":"Everton","home_team_phid":null,"home_team_logo":"\/\/dxnxhx88pdxyv.cloudfront.net\/logo\/32\/t499.png","home_team_short":"","away_team":"Manchester C","away_team_phid":null,"away_team_logo":"\/\/dxnxhx88pdxyv.cloudfront.net\/logo\/32\/t383.png","away_team_short":"Man C","phid":null},{"id":"64707","code":"SOCENGPRE","event_slug":"arsenal-west_bromwich-1401281","start":"1399206600","home_team":"Arsenal","home_team_phid":null,"home_team_logo":"\/\/dxnxhx88pdxyv.cloudfront.net\/logo\/32\/t30773.png","home_team_short":"","away_team":"West Bromwich","away_team_phid":null,"away_team_logo":"\/\/dxnxhx88pdxyv.cloudfront.net\/logo\/32\/t816.png","away_team_short":"West Brom","phid":null},{"id":"64705","code":"SOCENGPRE","event_slug":"chelsea-norwich-1401283","start":"1399215600","home_team":"Chelsea","home_team_phid":null,"home_team_logo":"\/\/dxnxhx88pdxyv.cloudfront.net\/logo\/32\/t497.png","home_team_short":"","away_team":"Norwich","away_team_phid":null,"away_team_logo":"\/\/dxnxhx88pdxyv.cloudfront.net\/logo\/32\/t1438.png","away_team_short":"","phid":null},{"id":"64708","code":"SOCENGPRE","event_slug":"crystal_palace-liverpool-1401284","start":"1399316400","home_team":"Crystal Palace","home_team_phid":null,"home_team_logo":"\/\/dxnxhx88pdxyv.cloudfront.net\/logo\/32\/t518.png","home_team_short":"C. Palace","away_team":"Liverpool","away_team_phid":null,"away_team_logo":"\/\/dxnxhx88pdxyv.cloudfront.net\/logo\/32\/t381.png","away_team_short":"","phid":null},{"id":"64679","code":"SOCENGPRE","event_slug":"manchester_u-hull-1401252","start":"1399401900","home_team":"Manchester U","home_team_phid":null,"home_team_logo":"\/\/dxnxhx88pdxyv.cloudfront.net\/logo\/32\/t20790.png","home_team_short":"Man U","away_team":"Hull","away_team_phid":null,"away_team_logo":"\/\/dxnxhx88pdxyv.cloudfront.net\/logo\/32\/t511.png","away_team_short":"Hull","phid":null},{"id":"64630","code":"SOCENGPRE","event_slug":"manchester_c-aston_villa-1401198","start":"1399488300","home_team":"Manchester C","home_team_phid":null,"home_team_logo":"\/\/dxnxhx88pdxyv.cloudfront.net\/logo\/32\/t383.png","home_team_short":"Man C","away_team":"Aston Villa","away_team_phid":null,"away_team_logo":"\/\/dxnxhx88pdxyv.cloudfront.net\/logo\/32\/t380.png","away_team_short":"","phid":null},{"id":"64621","code":"SOCENGPRE","event_slug":"sunderland-west_bromwich-1401189","start":"1399488300","home_team":"Sunderland","home_team_phid":null,"home_team_logo":"\/\/dxnxhx88pdxyv.cloudfront.net\/logo\/32\/t382.png","home_team_short":"","away_team":"West Bromwich","away_team_phid":null,"away_team_logo":"\/\/dxnxhx88pdxyv.cloudfront.net\/logo\/32\/t816.png","away_team_short":"West Brom","phid":null},{"id":"64719","code":"SOCENGPRE","event_slug":"manchester_c-west_ham-1401296","start":"1399816800","home_team":"Manchester C","home_team_phid":null,"home_team_logo":"\/\/dxnxhx88pdxyv.cloudfront.net\/logo\/32\/t383.png","home_team_short":"Man C","away_team":"West Ham","away_team_phid":null,"away_team_logo":"\/\/dxnxhx88pdxyv.cloudfront.net\/logo\/32\/t523.png","away_team_short":"","phid":null},{"id":"64717","code":"SOCENGPRE","event_slug":"liverpool-newcastle-1401295","start":"1399816800","home_team":"Liverpool","home_team_phid":null,"home_team_logo":"\/\/dxnxhx88pdxyv.cloudfront.net\/logo\/32\/t381.png","home_team_short":"","away_team":"Newcastle","away_team_phid":null,"away_team_logo":"\/\/dxnxhx88pdxyv.cloudfront.net\/logo\/32\/t385.png","away_team_short":"","phid":null},{"id":"64720","code":"SOCENGPRE","event_slug":"norwich-arsenal-1401297","start":"1399816800","home_team":"Norwich","home_team_phid":null,"home_team_logo":"\/\/dxnxhx88pdxyv.cloudfront.net\/logo\/32\/t1438.png","home_team_short":"","away_team":"Arsenal","away_team_phid":null,"away_team_logo":"\/\/dxnxhx88pdxyv.cloudfront.net\/logo\/32\/t30773.png","away_team_short":"","phid":null},{"id":"64715","code":"SOCENGPRE","event_slug":"fulham-crystal_palace-1401293","start":"1399816800","home_team":"Fulham","home_team_phid":null,"home_team_logo":"\/\/dxnxhx88pdxyv.cloudfront.net\/logo\/32\/t379.png","home_team_short":"","away_team":"Crystal Palace","away_team_phid":null,"away_team_logo":"\/\/dxnxhx88pdxyv.cloudfront.net\/logo\/32\/t518.png","away_team_short":"C. Palace","phid":null},{"id":"64722","code":"SOCENGPRE","event_slug":"sunderland-swansea-1401299","start":"1399816800","home_team":"Sunderland","home_team_phid":null,"home_team_logo":"\/\/dxnxhx88pdxyv.cloudfront.net\/logo\/32\/t382.png","home_team_short":"","away_team":"Swansea","away_team_phid":null,"away_team_logo":"\/\/dxnxhx88pdxyv.cloudfront.net\/logo\/32\/t384.png","away_team_short":"Swansea","phid":null},{"id":"64723","code":"SOCENGPRE","event_slug":"tottenham-aston_villa-1401300","start":"1399816800","home_team":"Tottenham","home_team_phid":null,"home_team_logo":"\/\/dxnxhx88pdxyv.cloudfront.net\/logo\/32\/t498.png","home_team_short":"","away_team":"Aston Villa","away_team_phid":null,"away_team_logo":"\/\/dxnxhx88pdxyv.cloudfront.net\/logo\/32\/t380.png","away_team_short":"","phid":null},{"id":"64724","code":"SOCENGPRE","event_slug":"west_bromwich-stoke-1401301","start":"1399816800","home_team":"West Bromwich","home_team_phid":null,"home_team_logo":"\/\/dxnxhx88pdxyv.cloudfront.net\/logo\/32\/t816.png","home_team_short":"West Brom","away_team":"Stoke","away_team_phid":null,"away_team_logo":"\/\/dxnxhx88pdxyv.cloudfront.net\/logo\/32\/t389.png","away_team_short":"","phid":null},{"id":"64718","code":"SOCENGPRE","event_slug":"hull-everton-1401294","start":"1399816800","home_team":"Hull","home_team_phid":null,"home_team_logo":"\/\/dxnxhx88pdxyv.cloudfront.net\/logo\/32\/t511.png","home_team_short":"Hull","away_team":"Everton","away_team_phid":null,"away_team_logo":"\/\/dxnxhx88pdxyv.cloudfront.net\/logo\/32\/t499.png","away_team_short":"","phid":null},{"id":"64721","code":"SOCENGPRE","event_slug":"southampton-manchester_u-1401298","start":"1399816800","home_team":"Southampton","home_team_phid":null,"home_team_logo":"\/\/dxnxhx88pdxyv.cloudfront.net\/logo\/32\/t8482.png","home_team_short":"","away_team":"Manchester U","away_team_phid":null,"away_team_logo":"\/\/dxnxhx88pdxyv.cloudfront.net\/logo\/32\/t20790.png","away_team_short":"Man U","phid":null},{"id":"64716","code":"SOCENGPRE","event_slug":"cardiff-chelsea-1401292","start":"1399816800","home_team":"Cardiff","home_team_phid":null,"home_team_logo":"\/\/dxnxhx88pdxyv.cloudfront.net\/logo\/32\/t524.png","home_team_short":"","away_team":"Chelsea","away_team_phid":null,"away_team_logo":"\/\/dxnxhx88pdxyv.cloudfront.net\/logo\/32\/t497.png","away_team_short":"","phid":null}]}});
Link to pastebin for easier reading of the data
Change your getResults function to be called after the JSON has been parsed, like so:
var myDataVar;
$.ajax({
url: "URL to JSON file here",
dataType: "text", //If you get an error here, change the type to "text"
success: function (data) {
myDataVar = $.parseJSON(data);
getResults();
}
});
The above code will save the JSON file's parsed data into a single variable.
It will then call a function to get the results, being this function:
function getResults() {
var fixturesLength = myDataVar.SOCENGPRE.fixtures.length - 1;
for (var i = 0; i <= fixturesLength; i++) {
console.log(myDataVar.SOCENGPRE.fixtures[i].id);
}
}
The above loop will print to the console every one of your fixtures ID's.
Test data used:
{
"SOCENGPRE": {
"league_name": "Barclays Premier League",
"league_phid": null,
"league_type": null,
"fixtures": [{
"id": "64714",
"code": "SOCENGPRE",
"event_slug": "west_ham-tottenham-1401290",
"start": "1399117500",
"home_team": "West Ham",
"home_team_phid": null,
"home_team_logo": "\/\/dxnxhx88pdxyv.cloudfront.net\/logo\/32\/t523.png",
"home_team_short": "",
"away_team": "Tottenham",
"away_team_phid": null,
"away_team_logo": "\/\/dxnxhx88pdxyv.cloudfront.net\/logo\/32\/t498.png",
"away_team_short": "",
"phid": null
}, {
"id": "64711",
"code": "SOCENGPRE",
"event_slug": "manchester_u-sunderland-1401286",
"start": "1399125600",
"home_team": "Manchester U",
"home_team_phid": null,
"home_team_logo": "\/\/dxnxhx88pdxyv.cloudfront.net\/logo\/32\/t20790.png",
"home_team_short": "Man U",
"away_team": "Sunderland",
"away_team_phid": null,
"away_team_logo": "\/\/dxnxhx88pdxyv.cloudfront.net\/logo\/32\/t382.png",
"away_team_short": "",
"phid": null
}, {
"id": "64712",
"code": "SOCENGPRE",
"event_slug": "stoke-fulham-1401288",
"start": "1399125600",
"home_team": "Stoke",
"home_team_phid": null,
"home_team_logo": "\/\/dxnxhx88pdxyv.cloudfront.net\/logo\/32\/t389.png",
"home_team_short": "",
"away_team": "Fulham",
"away_team_phid": null,
"away_team_logo": "\/\/dxnxhx88pdxyv.cloudfront.net\/logo\/32\/t379.png",
"away_team_short": "",
"phid": null
}]
}
}
Console results:
64714
64711
64712

Categories