I want to compare the results I get back from filling out a form to the properties returned from json.
I am not sure about how to go over that.
This is what I have so far:
$('#btn').on('click', function() {
let $inputs = $('#new_form :input');
let new_vals = {};
$inputs.each(function() {
new_form[this.id] = $(this).val();
});
console.log(new_vals);
$.getJSON(api, function(data) {
data.forEach(d => {
console.log(d.values);
});
});
});
My console.log() for new_vals
: {start_date: "2019-12-25", end_date: "2020-04-15"}
my console.log() for d.values
:
{start_date: "2020-01-01", end_date: "2020-03-15"}
{start_date: "2020-01-01", end_date: "2020-03-15"}
{start_date: "2019-12-25", end_date: "2020-04-15"}
{start_date: "2020-03-20", end_date: "2020-03-31"}
{start_date: "2019-10-01", end_date: "2020-03-31"}
{start_date: "2019-10-01", end_date: "2020-03-31"}
{start_date: "2020-01-01", end_date: "2020-01-31"}
{start_date: "2020-01-19", end_date: "2020-01-25"}
I want to compare both start_date
and end_date
to the properties in d.values
and want to return the ones that match.
I want the 3rd value ({start_date: "2019-12-25", end_date: "2020-04-15"}
) to be returned from the comparison above.
How do I do that?