I have this JS Array ...
var arr = [{
"Event_code": "BW-087",
"Interest_area": "Information technology",
"Start_time": "9:00 AM",
"End_time": "3:00 PM",
"Session_type": "Experience",
"all_day_evt": true
}, {
"Event_code": "BW-161",
"Interest_area": "Media, Communication and creative arts",
"Start_time": "9:00 AM",
"End_time": "3:00 PM",
"Session_type": "Experience",
"all_day_evt": true
}, {
"Event_code": "BW-114",
"Interest_area": "Nursing and midwifery",
"Start_time": "9:00 AM",
"End_time": "3:00 PM",
"Session_type": "Tour",
"all_day_evt": true
}, {
"Event_code": "BW-033",
"Interest_area": "",
"Start_time": "9:00 AM",
"End_time": "3:00 PM",
"Session_type": "General information session",
"all_day_evt": true
}, {
"Event_code": "BW-115",
"Interest_area": "Food, Nutrition and dietetics",
"Start_time": "9:30 AM",
"End_time": "3:00 PM",
"Session_type": "Tour",
"all_day_evt": true
}, {
"Event_code": "BW-060",
"Interest_area": "Sport",
"Start_time": "9:30 AM",
"End_time": "3:00 PM",
"Session_type": "Tour",
"all_day_evt": true
}, {
"Event_code": "BW-081",
"Interest_area": "Information technology",
"Start_time": "9:00 AM",
"End_time": "9:30 AM",
"Session_type": "Course information session",
"all_day_evt": false
}, {
"Event_code": "BW-170",
"Interest_area": "",
"Start_time": "9:30 AM",
"End_time": "10:30 AM",
"Session_type": "General information session",
"all_day_evt": false,
"clash": "This clashes with another session"
}, {
"Event_code": "BW-032",
"Interest_area": "",
"Start_time": "9:30 AM",
"End_time": "10:00 AM",
"Session_type": "General information session",
"all_day_evt": false
}, {
"Event_code": "BW-096",
"Interest_area": "Media, Communication and creative arts",
"Start_time": "10:00 AM",
"End_time": "12:00 PM",
"Session_type": "Experience",
"all_day_evt": false
}, {
"Event_code": "BW-163",
"Interest_area": "Business",
"Start_time": "10:00 AM",
"End_time": "2:00 PM",
"Session_type": "Experience",
"all_day_evt": false,
"clash": "This clashes with another session"
}, {
"Event_code": "BW-048",
"Interest_area": "Media, Communication and creative arts",
"Start_time": "12:00 PM",
"End_time": "12:30 PM",
"Session_type": "Experience",
"all_day_evt": false
}, {
"Event_code": "BW-128",
"Interest_area": "Media, Communication and creative arts",
"Start_time": "12:00 PM",
"End_time": "12:30 PM",
"Session_type": "Tour",
"all_day_evt": false,
"clash": "This clashes with another session"
}, {
"Event_code": "BW-018",
"Interest_area": "Sciences",
"Start_time": "12:30 PM",
"End_time": "2:30 PM",
"Session_type": "Tour",
"all_day_evt": false,
"clash": "This clashes with another session"
}, {
"Event_code": "BW-013",
"Interest_area": "Sciences, Engineering, Information technology, Architecture and built environment, Environment",
"Start_time": "12:30 PM",
"End_time": "1:00 PM",
"Session_type": "Course information session",
"all_day_evt": false
}, {
"Event_code": "BW-039",
"Interest_area": "Media, Communication and creative arts",
"Start_time": "1:00 PM",
"End_time": "1:30 PM",
"Session_type": "Experience",
"all_day_evt": false
}, {
"Event_code": "BW-162",
"Interest_area": "Education and teaching",
"Start_time": "1:00 PM",
"End_time": "1:30 PM",
"Session_type": "Tour",
"all_day_evt": false,
"clash": "This clashes with another session"
}]
arr.sort((x,y) => y.all_day_evt- x.all_day_evt || ((new Date('1970/01/01 ' + x.Start_time)) - (new Date('1970/01/01 ' + y.Start_time))));
console.log(arr);
I am looking to do 3 operations on this array ...
Group this array by "all_day_evt" key.
Sort this array within the 'true' subgroup, and 'false' subgroup by 'Start_time'.
Sort if there is a "clash" on 'start_time' ... with the "clashed event" showing up 2nd.
I am not sure how to implement the 3rd condition, any help is very appreciated. Thanks
Sample output shown below - highlighting how the clash events should line up. It should show up so that the event with "clash" key comes 2nd, not first.
For example, events "BW-013" & "BW-018" are clashing at start_time of 12:30 PM. So, 'BW-013' comes first, and then 'BW-018' shows up. Same goes with events 'BW-039' and 'BW-162' as shown in example output below.
[{
"Event_code": "BW-013",
"Interest_area": "Sciences, Engineering, Information technology, Architecture and built environment, Environment",
"Start_time": "12:30 PM",
"End_time": "1:00 PM",
"Session_type": "Course information session",
"all_day_evt": false
},
{
"Event_code": "BW-018",
"Interest_area": "Sciences",
"Start_time": "12:30 PM",
"End_time": "2:30 PM",
"Session_type": "Tour",
"all_day_evt": false,
"clash": "This clashes with another session"
},
{
"Event_code": "BW-039",
"Interest_area": "Media, Communication and creative arts",
"Start_time": "1:00 PM",
"End_time": "1:30 PM",
"Session_type": "Experience",
"all_day_evt": false
}, {
"Event_code": "BW-162",
"Interest_area": "Education and teaching",
"Start_time": "1:00 PM",
"End_time": "1:30 PM",
"Session_type": "Tour",
"all_day_evt": false,
"clash": "This clashes with another session"
}
]
Try following. You need to add additional condition of clash
var arr = [{"Event_code":"BW-087","Interest_area":"Information technology","Start_time":"9:00 AM","End_time":"3:00 PM","Session_type":"Experience","all_day_evt":true},{"Event_code":"BW-161","Interest_area":"Media, Communication and creative arts","Start_time":"9:00 AM","End_time":"3:00 PM","Session_type":"Experience","all_day_evt":true},{"Event_code":"BW-114","Interest_area":"Nursing and midwifery","Start_time":"9:00 AM","End_time":"3:00 PM","Session_type":"Tour","all_day_evt":true},{"Event_code":"BW-033","Interest_area":"","Start_time":"9:00 AM","End_time":"3:00 PM","Session_type":"General information session","all_day_evt":true},{"Event_code":"BW-115","Interest_area":"Food, Nutrition and dietetics","Start_time":"9:30 AM","End_time":"3:00 PM","Session_type":"Tour","all_day_evt":true},{"Event_code":"BW-060","Interest_area":"Sport","Start_time":"9:30 AM","End_time":"3:00 PM","Session_type":"Tour","all_day_evt":true},{"Event_code":"BW-081","Interest_area":"Information technology","Start_time":"9:00 AM","End_time":"9:30 AM","Session_type":"Course information session","all_day_evt":false},{"Event_code":"BW-170","Interest_area":"","Start_time":"9:30 AM","End_time":"10:30 AM","Session_type":"General information session","all_day_evt":false,"clash":"This clashes with another session"},{"Event_code":"BW-032","Interest_area":"","Start_time":"9:30 AM","End_time":"10:00 AM","Session_type":"General information session","all_day_evt":false},{"Event_code":"BW-096","Interest_area":"Media, Communication and creative arts","Start_time":"10:00 AM","End_time":"12:00 PM","Session_type":"Experience","all_day_evt":false},{"Event_code":"BW-163","Interest_area":"Business","Start_time":"10:00 AM","End_time":"2:00 PM","Session_type":"Experience","all_day_evt":false,"clash":"This clashes with another session"},{"Event_code":"BW-048","Interest_area":"Media, Communication and creative arts","Start_time":"12:00 PM","End_time":"12:30 PM","Session_type":"Experience","all_day_evt":false},{"Event_code":"BW-128","Interest_area":"Media, Communication and creative arts","Start_time":"12:00 PM","End_time":"12:30 PM","Session_type":"Tour","all_day_evt":false,"clash":"This clashes with another session"},{"Event_code":"BW-018","Interest_area":"Sciences","Start_time":"12:30 PM","End_time":"2:30 PM","Session_type":"Tour","all_day_evt":false,"clash":"This clashes with another session"},{"Event_code":"BW-013","Interest_area":"Sciences, Engineering, Information technology, Architecture and built environment, Environment","Start_time":"12:30 PM","End_time":"1:00 PM","Session_type":"Course information session","all_day_evt":false},{"Event_code":"BW-039","Interest_area":"Media, Communication and creative arts","Start_time":"1:00 PM","End_time":"1:30 PM","Session_type":"Experience","all_day_evt":false},{"Event_code":"BW-162","Interest_area":"Education and teaching","Start_time":"1:00 PM","End_time":"1:30 PM","Session_type":"Tour","all_day_evt":false,"clash":"This clashes with another session"}];
arr.sort((x,y) => y.all_day_evt- x.all_day_evt || ((new Date('1970/01/01 ' + x.Start_time)) - (new Date('1970/01/01 ' + y.Start_time))) || Boolean(x.clash) - Boolean(y.clash));
console.log(arr);
I have a form that a user fills out. First the user selects a store. Then the user selects a date from a calendar, using the jQuery Datepicker plugin. Based on which store the user selects and which DAY of the week the user selects from the calendar (Monday, Tuesday, etc). then that will determine which times will appear in the third dropdown. Here is my html:
<form action="/CustomerService-FFEventBookAppointment">
<fieldset>
<div class="form-row"><label for="store">Preferred Store *</label>
<div class="chzn-row valid">
<select class="chzn-global-select input-select optional required" id="store" name="store">
<option value=""></option>
<option value="Martin Place">Martin Place</option>
<option value="Chatswood Chase">Chatswood Chase</option>
<option value="Emporium">Emporium</option>
<option value="Indooroopilly">Indooroopilly</option>
<option value="Collins Street">Collins Street</option>
<option value="DJ Market Street">DJ Market Street</option>
<option value="DJ Bourke Street Mens">DJ Bourke Street Mens</option>
<option value="DJ Bourke Street Womens">DJ Bourke Street Womens</option>
<option value="DJ Queen Street">DJ Queen Street</option>
<option value="DJ Rundle Mall">DJ Rundle Mall</option>
</select>
</div>
</div>
<div class="form-row"><label for="date">Date *</label>
And below is my JavaScript. You can view the full thing on my JS fiddle: https://jsfiddle.net/katherinekonn/qquprwhg/
<div class="chzn-row valid">
<input type="text" lass="chzn-global-select input-select optional required" id="datepicker" name="date">
</div>
</div>
<div class="form-row"><label for="time">Time * </label>
<div class="chzn-row valid">
<select class="chzn-global-select input-select optional required" id="time" name="time">
<option value=""></option>
</select>
</div>
</div>
var dayByStore = {
"Martin Place": ["Friday", "Saturday", "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday"],
"Chatswood Chase": ["Friday", "Saturday", "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday"],
};
var timeByDayByStore = {
"Martin Place":{
"Friday":[
"9:00 AM - 10:00 AM",
"6:00 PM - 7:00 PM"
],
"Saturday":[
"10:00 AM - 11:00 AM",
"11:00 AM - 12:00 PM",
"4:00 PM - 5:00 PM"
],
"Sunday":[
"11:00 AM - 12:00 PM",
"12:00 PM - 1:00 PM",
"2:00 PM - 3:00 PM",
"3:00 PM - 4:00 PM",
"4:00 PM - 5:00 PM"
],
"Monday":[
"9:00 AM - 10:00 AM",
"6:00 PM - 7:00 PM"
],
"Tuesday":[
"9:00 AM - 10:00 AM"
],
"Wednesday":[
"9:00 AM - 10:00 AM",
"6:00 PM - 7:00 PM"
],
"Thursday":[
"9:00 AM - 10:00 AM",
"7:00 PM - 8:00 PM"
],
},
"Chatswood Chase":{
"Friday":[
"10:00 AM - 11:00 AM",
"4:00 PM - 5:00 PM"
],
"Saturday":[
"9:00 AM - 10:00 AM",
"4:00 PM - 5:00 PM"
],
"Sunday":[
"10:00 AM - 11:00 AM",
"4:00 PM - 5:00 PM"
],
"Monday":[
"10:00 AM - 11:00 AM",
"4:00 PM - 5:00 PM"
],
"Tuesday":[
"10:00 AM - 11:00 AM",
"4:00 PM - 5:00 PM"
],
"Wednesday":[
"10:00 AM - 11:00 AM",
"11:00 AM - 12:00 PM",
"4:00 PM - 5:00 PM"
],
"Thursday":[
"8:00 PM - 9:00 PM"
],
},
};
$( function() {
$('#datepicker').datepicker({ dateFormat: 'DD, MM, d, yy' });
} );
$(document).ready(function(){
$(document).on('change', '#datepicker', function(){
var store = $('#store option:selected').val();
var timeOptions = "";
for (timeId in timeByDayByStore[store][date]) {
timeOptions += "<option value='" + timeByDayByStore[store][date][timeId] + "'>" + timeByDayByStore[store][date][timeId] + "</option>";
}
document.getElementById("time").innerHTML = timeOptions;
})
})
Can anyone help me with the function? I'm still very new, but I need to somehow have the time dropdown become populated by times based on what store and what day of the week from the calendar the user selects, and I can't quite figure out the logic. Help is greatly appreciated and thank you in advance!
Here is a working snippet,
where I only made modifications at the end of the JS.
I removed the "personal" parts to make the snippet shorter,
and added some comments in my code to make it clearer!
var dayByStore = {
"Martin Place": ["Friday", "Saturday", "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday"],
"Chatswood Chase": ["Friday", "Saturday", "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday"],
"Emporium": ["Friday", "Saturday", "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday"],
"Indooroopilly": ["Friday", "Saturday", "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday"],
"Collins Street": ["Friday", "Saturday", "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday"],
"DJ Market Street": ["Friday", "Saturday", "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday"],
"DJ Bourke Street Mens": ["Friday", "Saturday", "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday"],
"DJ Bourke Street Womens": ["Friday", "Saturday", "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday"],
"DJ Queen Street": ["Friday", "Saturday", "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday"],
"DJ Rundle Mall": ["Friday", "Saturday", "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday"],
};
var timeByDayByStore = {
"Martin Place": {
"Friday": [
"9:00 AM - 10:00 AM",
"10:00 AM - 11:00 AM",
"11:00 AM - 12:00 PM",
"12:00 PM - 1:00 PM",
"1:00 PM - 2:00 PM",
"2:00 PM - 3:00 PM",
"3:00 PM - 4:00 PM",
"4:00 PM - 5:00 PM",
"5:00 PM - 6:00 PM",
"6:00 PM - 7:00 PM"
],
"Saturday": [
"10:00 AM - 11:00 AM",
"11:00 AM - 12:00 PM",
"12:00 PM - 1:00 PM",
"1:00 PM - 2:00 PM",
"2:00 PM - 3:00 PM",
"3:00 PM - 4:00 PM",
"4:00 PM - 5:00 PM"
],
"Sunday": [
"11:00 AM - 12:00 PM",
"12:00 PM - 1:00 PM",
"1:00 PM - 2:00 PM",
"2:00 PM - 3:00 PM",
"3:00 PM - 4:00 PM",
"4:00 PM - 5:00 PM"
],
"Monday": [
"9:00 AM - 10:00 AM",
"10:00 AM - 11:00 AM",
"11:00 AM - 12:00 PM",
"12:00 PM - 1:00 PM",
"1:00 PM - 2:00 PM",
"2:00 PM - 3:00 PM",
"3:00 PM - 4:00 PM",
"4:00 PM - 5:00 PM",
"5:00 PM - 6:00 PM",
"6:00 PM - 7:00 PM"
],
"Tuesday": [
"9:00 AM - 10:00 AM",
"10:00 AM - 11:00 AM",
"11:00 AM - 12:00 PM",
"12:00 PM - 1:00 PM",
"1:00 PM - 2:00 PM",
"2:00 PM - 3:00 PM",
"3:00 PM - 4:00 PM",
"4:00 PM - 5:00 PM",
"5:00 PM - 6:00 PM",
"6:00 PM - 7:00 PM"
],
"Wednesday": [
"9:00 AM - 10:00 AM",
"10:00 AM - 11:00 AM",
"11:00 AM - 12:00 PM",
"12:00 PM - 1:00 PM",
"1:00 PM - 2:00 PM",
"2:00 PM - 3:00 PM",
"3:00 PM - 4:00 PM",
"4:00 PM - 5:00 PM",
"5:00 PM - 6:00 PM",
"6:00 PM - 7:00 PM"
],
"Thursday": [
"9:00 AM - 10:00 AM",
"10:00 AM - 11:00 AM",
"11:00 AM - 12:00 PM",
"12:00 PM - 1:00 PM",
"1:00 PM - 2:00 PM",
"2:00 PM - 3:00 PM",
"3:00 PM - 4:00 PM",
"4:00 PM - 5:00 PM",
"5:00 PM - 6:00 PM",
"6:00 PM - 7:00 PM",
"7:00 PM - 8:00 PM"
],
},
"Chatswood Chase": {
"Friday": [
"10:00 AM - 11:00 AM",
"11:00 AM - 12:00 PM",
"12:00 PM - 1:00 PM",
"1:00 PM - 2:00 PM",
"2:00 PM - 3:00 PM",
"3:00 PM - 4:00 PM",
"4:00 PM - 5:00 PM"
],
"Saturday": [
"9:00 AM - 10:00 AM",
"10:00 AM - 11:00 AM",
"11:00 AM - 12:00 PM",
"12:00 PM - 1:00 PM",
"1:00 PM - 2:00 PM",
"2:00 PM - 3:00 PM",
"3:00 PM - 4:00 PM",
"4:00 PM - 5:00 PM"
],
"Sunday": [
"10:00 AM - 11:00 AM",
"11:00 AM - 12:00 PM",
"12:00 PM - 1:00 PM",
"1:00 PM - 2:00 PM",
"2:00 PM - 3:00 PM",
"3:00 PM - 4:00 PM",
"4:00 PM - 5:00 PM"
],
"Monday": [
"10:00 AM - 11:00 AM",
"11:00 AM - 12:00 PM",
"12:00 PM - 1:00 PM",
"1:00 PM - 2:00 PM",
"2:00 PM - 3:00 PM",
"3:00 PM - 4:00 PM",
"4:00 PM - 5:00 PM"
],
"Tuesday": [
"10:00 AM - 11:00 AM",
"11:00 AM - 12:00 PM",
"12:00 PM - 1:00 PM",
"1:00 PM - 2:00 PM",
"2:00 PM - 3:00 PM",
"3:00 PM - 4:00 PM",
"4:00 PM - 5:00 PM"
],
"Wednesday": [
"10:00 AM - 11:00 AM",
"11:00 AM - 12:00 PM",
"12:00 PM - 1:00 PM",
"1:00 PM - 2:00 PM",
"2:00 PM - 3:00 PM",
"3:00 PM - 4:00 PM",
"4:00 PM - 5:00 PM"
],
"Thursday": [
"10:00 AM - 11:00 AM",
"11:00 AM - 12:00 PM",
"12:00 PM - 1:00 PM",
"1:00 PM - 2:00 PM",
"2:00 PM - 3:00 PM",
"3:00 PM - 4:00 PM",
"4:00 PM - 5:00 PM",
"5:00 PM - 6:00 PM",
"6:00 PM - 7:00 PM",
"7:00 PM - 8:00 PM",
"8:00 PM - 9:00 PM"
],
},
"Emporium": {
"Friday": [
"10:00 AM - 11:00 AM",
"11:00 AM - 12:00 PM",
"12:00 PM - 1:00 PM",
"1:00 PM - 2:00 PM",
"2:00 PM - 3:00 PM",
"3:00 PM - 4:00 PM",
"4:00 PM - 5:00 PM",
"5:00 PM - 6:00 PM",
"6:00 PM - 7:00 PM",
"7:00 PM - 8:00 PM",
"8:00 PM - 9:00 PM"
],
"Saturday": [
"10:00 AM - 11:00 AM",
"11:00 AM - 12:00 PM",
"12:00 PM - 1:00 PM",
"1:00 PM - 2:00 PM",
"2:00 PM - 3:00 PM",
"3:00 PM - 4:00 PM",
"4:00 PM - 5:00 PM",
"5:00 PM - 6:00 PM",
"6:00 PM - 7:00 PM"
],
"Sunday": [
"10:00 AM - 11:00 AM",
"11:00 AM - 12:00 PM",
"12:00 PM - 1:00 PM",
"1:00 PM - 2:00 PM",
"2:00 PM - 3:00 PM",
"3:00 PM - 4:00 PM",
"4:00 PM - 5:00 PM",
"5:00 PM - 6:00 PM",
"6:00 PM - 7:00 PM"
],
"Monday": [
"10:00 AM - 11:00 AM",
"11:00 AM - 12:00 PM",
"12:00 PM - 1:00 PM",
"1:00 PM - 2:00 PM",
"2:00 PM - 3:00 PM",
"3:00 PM - 4:00 PM",
"4:00 PM - 5:00 PM",
"5:00 PM - 6:00 PM",
"6:00 PM - 7:00 PM"
],
"Tuesday": [
"10:00 AM - 11:00 AM",
"11:00 AM - 12:00 PM",
"12:00 PM - 1:00 PM",
"1:00 PM - 2:00 PM",
"2:00 PM - 3:00 PM",
"3:00 PM - 4:00 PM",
"4:00 PM - 5:00 PM",
"5:00 PM - 6:00 PM",
"6:00 PM - 7:00 PM"
],
"Wesnesday": [
"10:00 AM - 11:00 AM",
"11:00 AM - 12:00 PM",
"12:00 PM - 1:00 PM",
"1:00 PM - 2:00 PM",
"2:00 PM - 3:00 PM",
"3:00 PM - 4:00 PM",
"4:00 PM - 5:00 PM",
"5:00 PM - 6:00 PM",
"6:00 PM - 7:00 PM"
],
"Thursday": [
"10:00 AM - 11:00 AM",
"11:00 AM - 12:00 PM",
"12:00 PM - 1:00 PM",
"1:00 PM - 2:00 PM",
"2:00 PM - 3:00 PM",
"3:00 PM - 4:00 PM",
"4:00 PM - 5:00 PM",
"5:00 PM - 6:00 PM",
"6:00 PM - 7:00 PM",
"7:00 PM - 8:00 PM",
"8:00 PM - 9:00 PM"
],
},
"Indooroopilly": {
"Friday": [
"9:00 AM - 10:00 AM",
"10:00 AM - 11:00 AM",
"11:00 AM - 12:00 PM",
"12:00 PM - 1:00 PM",
"1:00 PM - 2:00 PM",
"2:00 PM - 3:00 PM",
"3:00 PM - 4:00 PM",
"4:00 PM - 5:00 PM"
],
"Saturday": [
"9:00 AM - 10:00 AM",
"10:00 AM - 11:00 AM",
"11:00 AM - 12:00 PM",
"12:00 PM - 1:00 PM",
"1:00 PM - 2:00 PM",
"2:00 PM - 3:00 PM",
"3:00 PM - 4:00 PM",
"4:00 PM - 5:00 PM"
],
"Sunday": [
"10:00 AM - 11:00 AM",
"11:00 AM - 12:00 PM",
"12:00 PM - 1:00 PM",
"1:00 PM - 2:00 PM",
"2:00 PM - 3:00 PM",
"3:00 PM - 4:00 PM"
],
"Monday": [
"9:00 AM - 10:00 AM",
"10:00 AM - 11:00 AM",
"11:00 AM - 12:00 PM",
"12:00 PM - 1:00 PM",
"1:00 PM - 2:00 PM",
"2:00 PM - 3:00 PM",
"3:00 PM - 4:00 PM",
"4:00 PM - 5:00 PM"
],
"Tuesday": [
"9:00 AM - 10:00 AM",
"10:00 AM - 11:00 AM",
"11:00 AM - 12:00 PM",
"12:00 PM - 1:00 PM",
"1:00 PM - 2:00 PM",
"2:00 PM - 3:00 PM",
"3:00 PM - 4:00 PM",
"4:00 PM - 5:00 PM"
],
"Wednesday": [
"9:00 AM - 10:00 AM",
"10:00 AM - 11:00 AM",
"11:00 AM - 12:00 PM",
"12:00 PM - 1:00 PM",
"1:00 PM - 2:00 PM",
"2:00 PM - 3:00 PM",
"3:00 PM - 4:00 PM",
"4:00 PM - 5:00 PM"
],
"Thursday": [
"9:00 AM - 10:00 AM",
"10:00 AM - 11:00 AM",
"11:00 AM - 12:00 PM",
"12:00 PM - 1:00 PM",
"1:00 PM - 2:00 PM",
"2:00 PM - 3:00 PM",
"3:00 PM - 4:00 PM",
"4:00 PM - 5:00 PM",
"5:00 PM - 6:00 PM",
"6:00 PM - 7:00 PM",
"7:00 PM - 8:00 PM",
"8:00 PM - 9:00 PM"
],
},
"Collins Street": {
"Friday": [
"9:00 AM - 10:00 AM",
"10:00 AM - 11:00 AM",
"11:00 AM - 12:00 PM",
"12:00 PM - 1:00 PM",
"1:00 PM - 2:00 PM",
"2:00 PM - 3:00 PM",
"3:00 PM - 4:00 PM",
"4:00 PM - 5:00 PM",
"5:00 PM - 6:00 PM",
"6:00 PM - 7:00 PM"
],
"Saturday": [
"10:00 AM - 11:00 AM",
"11:00 AM - 12:00 PM",
"12:00 PM - 1:00 PM",
"1:00 PM - 2:00 PM",
"2:00 PM - 3:00 PM",
"3:00 PM - 4:00 PM",
"4:00 PM - 5:00 PM"
],
"Monday": [
"9:00 AM - 10:00 AM",
"10:00 AM - 11:00 AM",
"11:00 AM - 12:00 PM",
"12:00 PM - 1:00 PM",
"1:00 PM - 2:00 PM",
"2:00 PM - 3:00 PM",
"3:00 PM - 4:00 PM",
"4:00 PM - 5:00 PM",
"5:00 PM - 6:00 PM"
],
"Tuesday": [
"9:00 AM - 10:00 AM",
"10:00 AM - 11:00 AM",
"11:00 AM - 12:00 PM",
"12:00 PM - 1:00 PM",
"1:00 PM - 2:00 PM",
"2:00 PM - 3:00 PM",
"3:00 PM - 4:00 PM",
"4:00 PM - 5:00 PM",
"5:00 PM - 6:00 PM"
],
"Wednesday": [
"9:00 AM - 10:00 AM",
"10:00 AM - 11:00 AM",
"11:00 AM - 12:00 PM",
"12:00 PM - 1:00 PM",
"1:00 PM - 2:00 PM",
"2:00 PM - 3:00 PM",
"3:00 PM - 4:00 PM",
"4:00 PM - 5:00 PM",
"5:00 PM - 6:00 PM"
],
"Thursday": [
"9:00 AM - 10:00 AM",
"10:00 AM - 11:00 AM",
"11:00 AM - 12:00 PM",
"12:00 PM - 1:00 PM",
"1:00 PM - 2:00 PM",
"2:00 PM - 3:00 PM",
"3:00 PM - 4:00 PM",
"4:00 PM - 5:00 PM",
"5:00 PM - 6:00 PM"
],
},
"DJ Market Street": {
"Friday": [
"10:00 AM - 11:00 AM",
"11:00 AM - 12:00 PM",
"12:00 PM - 1:00 PM",
"1:00 PM - 2:00 PM",
"2:00 PM - 3:00 PM",
"3:00 PM - 4:00 PM",
"4:00 PM - 5:00 PM",
"5:00 PM - 6:00 PM",
"6:00 PM - 7:00 PM",
"7:00 PM - 8:00 PM",
"8:00 PM - 9:00 PM"
],
"Saturday": [
"9:00 AM - 10:00 AM",
"10:00 AM - 11:00 AM",
"11:00 AM - 12:00 PM",
"12:00 PM - 1:00 PM",
"1:00 PM - 2:00 PM",
"2:00 PM - 3:00 PM",
"3:00 PM - 4:00 PM",
"4:00 PM - 5:00 PM",
"5:00 PM - 6:00 PM",
"6:00 PM - 7:00 PM"
],
"Sunday": [
"10:00 AM - 11:00 AM",
"11:00 AM - 12:00 PM",
"12:00 PM - 1:00 PM",
"1:00 PM - 2:00 PM",
"2:00 PM - 3:00 PM",
"3:00 PM - 4:00 PM",
"4:00 PM - 5:00 PM",
"5:00 PM - 6:00 PM",
"6:00 PM - 7:00 PM"
],
"Monday": [
"10:00 AM - 11:00 AM",
"11:00 AM - 12:00 PM",
"12:00 PM - 1:00 PM",
"1:00 PM - 2:00 PM",
"2:00 PM - 3:00 PM",
"3:00 PM - 4:00 PM",
"4:00 PM - 5:00 PM",
"5:00 PM - 6:00 PM",
"6:00 PM - 7:00 PM"
],
"Tuesday": [
"10:00 AM - 11:00 AM",
"11:00 AM - 12:00 PM",
"12:00 PM - 1:00 PM",
"1:00 PM - 2:00 PM",
"2:00 PM - 3:00 PM",
"3:00 PM - 4:00 PM",
"4:00 PM - 5:00 PM",
"5:00 PM - 6:00 PM",
"6:00 PM - 7:00 PM"
],
"Wednesday": [
"10:00 AM - 11:00 AM",
"11:00 AM - 12:00 PM",
"12:00 PM - 1:00 PM",
"1:00 PM - 2:00 PM",
"2:00 PM - 3:00 PM",
"3:00 PM - 4:00 PM",
"4:00 PM - 5:00 PM",
"5:00 PM - 6:00 PM",
"6:00 PM - 7:00 PM"
],
"Thursday": [
"10:00 AM - 11:00 AM",
"11:00 AM - 12:00 PM",
"12:00 PM - 1:00 PM",
"1:00 PM - 2:00 PM",
"2:00 PM - 3:00 PM",
"3:00 PM - 4:00 PM",
"4:00 PM - 5:00 PM",
"5:00 PM - 6:00 PM",
"6:00 PM - 7:00 PM",
"7:00 PM - 8:00 PM",
"8:00 PM - 9:00 PM"
],
},
"DJ Bourke Street Mens": {
"Friday": [
"10:00 AM - 11:00 AM",
"11:00 AM - 12:00 PM",
"12:00 PM - 1:00 PM",
"1:00 PM - 2:00 PM",
"2:00 PM - 3:00 PM",
"3:00 PM - 4:00 PM",
"4:00 PM - 5:00 PM",
"5:00 PM - 6:00 PM",
"6:00 PM - 7:00 PM",
"7:00 PM - 8:00 PM",
"8:00 PM - 9:00 PM"
],
"Saturday": [
"10:00 AM - 11:00 AM",
"11:00 AM - 12:00 PM",
"12:00 PM - 1:00 PM",
"1:00 PM - 2:00 PM",
"2:00 PM - 3:00 PM",
"3:00 PM - 4:00 PM",
"4:00 PM - 5:00 PM",
"5:00 PM - 6:00 PM",
"6:00 PM - 7:00 PM"
],
"Sunday": [
"10:00 AM - 11:00 AM",
"11:00 AM - 12:00 PM",
"12:00 PM - 1:00 PM",
"1:00 PM - 2:00 PM",
"2:00 PM - 3:00 PM",
"3:00 PM - 4:00 PM",
"4:00 PM - 5:00 PM",
"5:00 PM - 6:00 PM",
"6:00 PM - 7:00 PM"
],
"Monday": [
"10:00 AM - 11:00 AM",
"11:00 AM - 12:00 PM",
"12:00 PM - 1:00 PM",
"1:00 PM - 2:00 PM",
"2:00 PM - 3:00 PM",
"3:00 PM - 4:00 PM",
"4:00 PM - 5:00 PM",
"5:00 PM - 6:00 PM",
"6:00 PM - 7:00 PM"
],
"Tuesday": [
"10:00 AM - 11:00 AM",
"11:00 AM - 12:00 PM",
"12:00 PM - 1:00 PM",
"1:00 PM - 2:00 PM",
"2:00 PM - 3:00 PM",
"3:00 PM - 4:00 PM",
"4:00 PM - 5:00 PM",
"5:00 PM - 6:00 PM",
"6:00 PM - 7:00 PM"
],
"Wednesday": [
"10:00 AM - 11:00 AM",
"11:00 AM - 12:00 PM",
"12:00 PM - 1:00 PM",
"1:00 PM - 2:00 PM",
"2:00 PM - 3:00 PM",
"3:00 PM - 4:00 PM",
"4:00 PM - 5:00 PM",
"5:00 PM - 6:00 PM",
"6:00 PM - 7:00 PM"
],
"Thursday": [
"10:00 AM - 11:00 AM",
"11:00 AM - 12:00 PM",
"12:00 PM - 1:00 PM",
"1:00 PM - 2:00 PM",
"2:00 PM - 3:00 PM",
"3:00 PM - 4:00 PM",
"4:00 PM - 5:00 PM",
"5:00 PM - 6:00 PM",
"6:00 PM - 7:00 PM",
"7:00 PM - 8:00 PM",
"8:00 PM - 9:00 PM"
],
},
"DJ Bourke Street Womens": {
"Friday": [
"10:00 AM - 11:00 AM",
"11:00 AM - 12:00 PM",
"12:00 PM - 1:00 PM",
"1:00 PM - 2:00 PM",
"2:00 PM - 3:00 PM",
"3:00 PM - 4:00 PM",
"4:00 PM - 5:00 PM",
"5:00 PM - 6:00 PM",
"6:00 PM - 7:00 PM",
"7:00 PM - 8:00 PM",
"8:00 PM - 9:00 PM"
],
"Saturday": [
"10:00 AM - 11:00 AM",
"11:00 AM - 12:00 PM",
"12:00 PM - 1:00 PM",
"1:00 PM - 2:00 PM",
"2:00 PM - 3:00 PM",
"3:00 PM - 4:00 PM",
"4:00 PM - 5:00 PM",
"5:00 PM - 6:00 PM",
"6:00 PM - 7:00 PM"
],
"Sunday": [
"10:00 AM - 11:00 AM",
"11:00 AM - 12:00 PM",
"12:00 PM - 1:00 PM",
"1:00 PM - 2:00 PM",
"2:00 PM - 3:00 PM",
"3:00 PM - 4:00 PM",
"4:00 PM - 5:00 PM",
"5:00 PM - 6:00 PM",
"6:00 PM - 7:00 PM"
],
"Monday": [
"10:00 AM - 11:00 AM",
"11:00 AM - 12:00 PM",
"12:00 PM - 1:00 PM",
"1:00 PM - 2:00 PM",
"2:00 PM - 3:00 PM",
"3:00 PM - 4:00 PM",
"4:00 PM - 5:00 PM",
"5:00 PM - 6:00 PM",
"6:00 PM - 7:00 PM"
],
"Tuesday": [
"10:00 AM - 11:00 AM",
"11:00 AM - 12:00 PM",
"12:00 PM - 1:00 PM",
"1:00 PM - 2:00 PM",
"2:00 PM - 3:00 PM",
"3:00 PM - 4:00 PM",
"4:00 PM - 5:00 PM",
"5:00 PM - 6:00 PM",
"6:00 PM - 7:00 PM"
],
"Wednesday": [
"10:00 AM - 11:00 AM",
"11:00 AM - 12:00 PM",
"12:00 PM - 1:00 PM",
"1:00 PM - 2:00 PM",
"2:00 PM - 3:00 PM",
"3:00 PM - 4:00 PM",
"4:00 PM - 5:00 PM",
"5:00 PM - 6:00 PM",
"6:00 PM - 7:00 PM"
],
"Thursday": [
"10:00 AM - 11:00 AM",
"11:00 AM - 12:00 PM",
"12:00 PM - 1:00 PM",
"1:00 PM - 2:00 PM",
"2:00 PM - 3:00 PM",
"3:00 PM - 4:00 PM",
"4:00 PM - 5:00 PM",
"5:00 PM - 6:00 PM",
"6:00 PM - 7:00 PM",
"7:00 PM - 8:00 PM",
"8:00 PM - 9:00 PM"
],
},
"DJ Queen Street": {
"Friday": [
"10:00 AM - 11:00 AM",
"11:00 AM - 12:00 PM",
"12:00 PM - 1:00 PM",
"1:00 PM - 2:00 PM",
"2:00 PM - 3:00 PM",
"3:00 PM - 4:00 PM",
"4:00 PM - 5:00 PM",
"5:00 PM - 6:00 PM",
"6:00 PM - 7:00 PM",
"7:00 PM - 8:00 PM",
"8:00 PM - 9:00 PM"
],
"Saturday": [
"9:00 AM - 10:00 AM",
"10:00 AM - 11:00 AM",
"11:00 AM - 12:00 PM",
"12:00 PM - 1:00 PM",
"1:00 PM - 2:00 PM",
"2:00 PM - 3:00 PM",
"3:00 PM - 4:00 PM",
"4:00 PM - 5:00 PM"
],
"Sunday": [
"10:00 AM - 11:00 AM",
"11:00 AM - 12:00 PM",
"12:00 PM - 1:00 PM",
"1:00 PM - 2:00 PM",
"2:00 PM - 3:00 PM",
"3:00 PM - 4:00 PM",
"4:00 PM - 5:00 PM",
"5:00 PM - 6:00 PM"
],
"Monday": [
"10:00 AM - 11:00 AM",
"11:00 AM - 12:00 PM",
"12:00 PM - 1:00 PM",
"1:00 PM - 2:00 PM",
"2:00 PM - 3:00 PM",
"3:00 PM - 4:00 PM",
"4:00 PM - 5:00 PM",
"5:00 PM - 6:00 PM",
"6:00 PM - 7:00 PM"
],
"Tuesday": [
"10:00 AM - 11:00 AM",
"11:00 AM - 12:00 PM",
"12:00 PM - 1:00 PM",
"1:00 PM - 2:00 PM",
"2:00 PM - 3:00 PM",
"3:00 PM - 4:00 PM",
"4:00 PM - 5:00 PM",
"5:00 PM - 6:00 PM",
"6:00 PM - 7:00 PM"
],
"Wednesday": [
"10:00 AM - 11:00 AM",
"11:00 AM - 12:00 PM",
"12:00 PM - 1:00 PM",
"1:00 PM - 2:00 PM",
"2:00 PM - 3:00 PM",
"3:00 PM - 4:00 PM",
"4:00 PM - 5:00 PM",
"5:00 PM - 6:00 PM",
"6:00 PM - 7:00 PM"
],
"Thursday": [
"10:00 AM - 11:00 AM",
"11:00 AM - 12:00 PM",
"12:00 PM - 1:00 PM",
"1:00 PM - 2:00 PM",
"2:00 PM - 3:00 PM",
"3:00 PM - 4:00 PM",
"4:00 PM - 5:00 PM",
"5:00 PM - 6:00 PM",
"6:00 PM - 7:00 PM",
"7:00 PM - 8:00 PM",
"8:00 PM - 9:00 PM"
],
},
"DJ Rundle Mall": {
"Friday": [
"10:00 AM - 11:00 AM",
"11:00 AM - 12:00 PM",
"12:00 PM - 1:00 PM",
"1:00 PM - 2:00 PM",
"2:00 PM - 3:00 PM",
"3:00 PM - 4:00 PM",
"4:00 PM - 5:00 PM",
"5:00 PM - 6:00 PM",
"6:00 PM - 7:00 PM",
"7:00 PM - 8:00 PM",
"8:00 PM - 9:00 PM"
],
"Saturday": [
"9:00 AM - 10:00 AM",
"10:00 AM - 11:00 AM",
"11:00 AM - 12:00 PM",
"12:00 PM - 1:00 PM",
"1:00 PM - 2:00 PM",
"2:00 PM - 3:00 PM",
"3:00 PM - 4:00 PM",
"4:00 PM - 5:00 PM"
],
"Sunday": [
"11:00 AM - 12:00 PM",
"12:00 PM - 1:00 PM",
"1:00 PM - 2:00 PM",
"2:00 PM - 3:00 PM",
"3:00 PM - 4:00 PM",
"4:00 PM - 5:00 PM"
],
"Monday": [
"10:00 AM - 11:00 AM",
"11:00 AM - 12:00 PM",
"12:00 PM - 1:00 PM",
"1:00 PM - 2:00 PM",
"2:00 PM - 3:00 PM",
"3:00 PM - 4:00 PM",
"4:00 PM - 5:00 PM",
"5:00 PM - 6:00 PM",
"6:00 PM - 7:00 PM"
],
"Tuesday": [
"10:00 AM - 11:00 AM",
"11:00 AM - 12:00 PM",
"12:00 PM - 1:00 PM",
"1:00 PM - 2:00 PM",
"2:00 PM - 3:00 PM",
"3:00 PM - 4:00 PM",
"4:00 PM - 5:00 PM",
"5:00 PM - 6:00 PM",
"6:00 PM - 7:00 PM"
],
"Wednesday": [
"10:00 AM - 11:00 AM",
"11:00 AM - 12:00 PM",
"12:00 PM - 1:00 PM",
"1:00 PM - 2:00 PM",
"2:00 PM - 3:00 PM",
"3:00 PM - 4:00 PM",
"4:00 PM - 5:00 PM",
"5:00 PM - 6:00 PM",
"6:00 PM - 7:00 PM"
],
"Thursday": [
"10:00 AM - 11:00 AM",
"11:00 AM - 12:00 PM",
"12:00 PM - 1:00 PM",
"1:00 PM - 2:00 PM",
"2:00 PM - 3:00 PM",
"3:00 PM - 4:00 PM",
"4:00 PM - 5:00 PM",
"5:00 PM - 6:00 PM",
"6:00 PM - 7:00 PM",
"7:00 PM - 8:00 PM",
"8:00 PM - 9:00 PM"
],
},
};
var user_store = '';
var user_day = '';
// Function where the options are updated
function update_time() {
// Empty the options list
$('#time').empty();
// Exits function if there's no store, or no day.
if (!user_store || !user_day) return;
// Gets the open hours of the user selected store and day
var open_hours = timeByDayByStore[user_store][user_day];
// Fills the options list
$.each(open_hours, function(key, value) {
$('#time')
.append($("<option></option>")
.attr("value", key)
.text(value));
});
}
$(function() {
$('#datepicker').datepicker({
dateFormat: 'DD, MM, d, yy',
// Added action on selection of a date
onSelect: function(dateText, inst) {
// Here, we split the value of the datepicker to get the day, like "Monday"
user_day = dateText.split(',')[0];
// Then, we call the update function!
update_time();
}
});
});
// Call the function when changing the store, too!
$('#store').on('change', function(){
user_store = $('#store').val();
update_time();
});
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>jQuery UI Datepicker - Default functionality</title>
<link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
</head>
<body>
<div class="ffEventContainer">
<div id="ffEvent">
<div id="ffHeader">
<div class="line"> </div>
<div class="line lineRight"> </div>
<h1>Time & Venue</h1>
</div>
<div id="ffLanding">
<form action="/CustomerService-FFEventBookAppointment">
<fieldset>
<div class="form-row"><label for="store">Preferred Store *</label>
<div class="chzn-row valid">
<select class="chzn-global-select input-select optional required" id="store" name="store">
<option value=""></option>
<option value="Martin Place">Martin Place</option>
<option value="Chatswood Chase">Chatswood Chase</option>
<option value="Emporium">Emporium</option>
<option value="Indooroopilly">Indooroopilly</option>
<option value="Collins Street">Collins Street</option>
<option value="DJ Market Street">DJ Market Street</option>
<option value="DJ Bourke Street Mens">DJ Bourke Street Mens</option>
<option value="DJ Bourke Street Womens">DJ Bourke Street Womens</option>
<option value="DJ Queen Street">DJ Queen Street</option>
<option value="DJ Rundle Mall">DJ Rundle Mall</option>
</select>
</div>
</div>
<div class="form-row"><label for="date">Date *</label>
<div class="chzn-row valid">
<input type="text" lass="chzn-global-select input-select optional required" id="datepicker" name="date">
</div>
</div>
<div class="form-row"><label for="time">Time * </label>
<div class="chzn-row valid">
<select class="chzn-global-select input-select optional required" id="time" name="time">
<option value=""></option>
</select>
</div>
</div>
</fieldset>
</form>
</div>
</div>
</div>
</body>
</html>
I hope it helps.
You may take a look on my JS fiddle: https://jsfiddle.net/1bx2ccb0/1/
const time = document.getElementById("time");
$(document).ready(function() {
$(document).on('change', '#datepicker', function() {
var store = $('#store option:selected').val();
const date = document.getElementById("datepicker").value.split(',')[0];
time.innerHTML = "";
timeByDayByStore[store][date].forEach(timeByDay => {
const option = new Option(timeByDay, timeByDay)
time.add(option);
});
})
})
I have following JSON
[{ "GameID":"1109100", "StartTime": "4:00 PM", "EndTime": "1/1/1900 5:30:00 PM", "Duration": "90","TeamID":"101567"},{ "GameID":"1108768", "StartTime": "12:00 PM", "EndTime": "1/1/1900 1:30:00 PM", "Duration": "90","TeamID":"109873"},{ "GameID":"1108776", "StartTime": "12:00 PM", "EndTime": "1/1/1900 1:30:00 PM", "Duration": "90","TeamID":"117674"},{ "GameID":"1108742", "StartTime": "9:00 AM", "EndTime": "1/1/1900 10:30:00 AM", "Duration": "90","TeamID":"24621"},{ "GameID":"1108751", "StartTime": "9:00 AM", "EndTime": "1/1/1900 10:30:00 AM", "Duration": "90","TeamID":"24622"},{ "GameID":"1108757", "StartTime": "10:30 AM", "EndTime": "1/1/1900 12:00:00 PM", "Duration": "90","TeamID":"24623"},{ "GameID":"1109098", "StartTime": "2:30 PM", "EndTime": "1/1/1900 4:00:00 PM", "Duration": "90","TeamID":"24746"}]
I want to get game id, start time and end time value using TeamID. How can I do this ?
Edit: Actual function to parse JSON from comments
function doParseTime(msg){
var data = $.parseJSON(msg);
$.each(data, function() {
$.each(this, function(key, val){
$("#"+key).val(val);
});
});
}
Here a simple code-snippet how to access your json-keys:
$(document).ready(function(){
msg = '[{ "GameID":"1109100", "StartTime": "4:00 PM", "EndTime": "1/1/1900 5:30:00 PM", "Duration": "90","TeamID":"101567"},{ "GameID":"1108768", "StartTime": "12:00 PM", "EndTime": "1/1/1900 1:30:00 PM", "Duration": "90","TeamID":"109873"},{ "GameID":"1108776", "StartTime": "12:00 PM", "EndTime": "1/1/1900 1:30:00 PM", "Duration": "90","TeamID":"117674"},{ "GameID":"1108742", "StartTime": "9:00 AM", "EndTime": "1/1/1900 10:30:00 AM", "Duration": "90","TeamID":"24621"},{ "GameID":"1108751", "StartTime": "9:00 AM", "EndTime": "1/1/1900 10:30:00 AM", "Duration": "90","TeamID":"24622"},{ "GameID":"1108757", "StartTime": "10:30 AM", "EndTime": "1/1/1900 12:00:00 PM", "Duration": "90","TeamID":"24623"},{ "GameID":"1109098", "StartTime": "2:30 PM", "EndTime": "1/1/1900 4:00:00 PM", "Duration": "90","TeamID":"24746"}] ';
$.each(JSON.parse(msg), function(idx, obj) {
var gameid = obj.GameID;
var starttime = obj.StartTime;
var endtime = obj.EndTime;
});
});
Next time please read more in google about parsing and accessing json with jquery or javascript ;)
var yourJsonStr='[{ "GameID":"1109100", "StartTime": "4:00 PM", "EndTime": "1/1/1900 5:30:00 PM", "Duration": "90","TeamID":"101567"},{ "GameID":"1108768", "StartTime": "12:00 PM", "EndTime": "1/1/1900 1:30:00 PM", "Duration": "90","TeamID":"109873"},{ "GameID":"1108776", "StartTime": "12:00 PM", "EndTime": "1/1/1900 1:30:00 PM", "Duration": "90","TeamID":"117674"},{ "GameID":"1108742", "StartTime": "9:00 AM", "EndTime": "1/1/1900 10:30:00 AM", "Duration": "90","TeamID":"24621"},{ "GameID":"1108751", "StartTime": "9:00 AM", "EndTime": "1/1/1900 10:30:00 AM", "Duration": "90","TeamID":"24622"},{ "GameID":"1108757", "StartTime": "10:30 AM", "EndTime": "1/1/1900 12:00:00 PM", "Duration": "90","TeamID":"24623"},{ "GameID":"1109098", "StartTime": "2:30 PM", "EndTime": "1/1/1900 4:00:00 PM", "Duration": "90","TeamID":"24746"}]';
var gameInfo=eval("("+yourJsonStr+")");
$.each(gameInfo,function(i,item){
$('#gameId').append((i + 1) + ": " + item.GameID + "<br/>");
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js"></script>
<div id="gameId"></div>
Try with JSON.parse() ,Array#filter and Array#map
var data = '[{ "GameID":"1109100", "StartTime": "4:00 PM", "EndTime": "1/1/1900 5:30:00 PM", "Duration": "90","TeamID":"101567"},{ "GameID":"1108768", "StartTime": "12:00 PM", "EndTime": "1/1/1900 1:30:00 PM", "Duration": "90","TeamID":"109873"},{ "GameID":"1108776", "StartTime": "12:00 PM", "EndTime": "1/1/1900 1:30:00 PM", "Duration": "90","TeamID":"117674"},{ "GameID":"1108742", "StartTime": "9:00 AM", "EndTime": "1/1/1900 10:30:00 AM", "Duration": "90","TeamID":"24621"},{ "GameID":"1108751", "StartTime": "9:00 AM", "EndTime": "1/1/1900 10:30:00 AM", "Duration": "90","TeamID":"24622"},{ "GameID":"1108757", "StartTime": "10:30 AM", "EndTime": "1/1/1900 12:00:00 PM", "Duration": "90","TeamID":"24623"},{ "GameID":"1109098", "StartTime": "2:30 PM", "EndTime": "1/1/1900 4:00:00 PM", "Duration": "90","TeamID":"24746"}]';
function finding(id){
var f = JSON.parse(data).filter(a=> a.TeamID == id) //it will the matched teamId
return f.map(a=> {return {
GameID : a.GameID,
StartTime: a.StartTime,
EndTime : a.EndTime,
}}) // it add compress with three key value and iterate the all matched object's
}
console.log(finding(109873))
Parse the JSON if it's a string, then iterate over the array of objects by using
Array.find().
From the docs:
The find() method returns the value of the first element in the array
that satisfies the provided testing function. Otherwise undefined is
returned.
let json = JSON.parse(yourJsonString);
let teamID= yourTeamID;
//json is an array of javascript objects. Iterate over them with "find";
//This will return the first instance where the expression evaluates to true
let foundObject = json.find(obj=>{
return obj.TeamID=== teamID;
});
let gameID = foundObject.GameID;
let startTime = foundObject.StartTime;
let endTime = foundObject.EndTime;
Hope this helps.