I am trying to find an object in an array that meets specific conditions. I have an array created from a CSV file that gives the following result:
0: {production_company: "Columbia Pictures", Pass: 50, Fail: 65, total: 115}
1: {production_company: "Universal Pictures", Pass: 47, Fail: 65, total: 112}
2: {production_company: "Warner Bros.", Pass: 38, Fail: 74, total: 112}
Then I have a dropdown menu with checkboxes where I check which one was "checked" using jQuery selector and on Change handler. I can get the attribute id so far. In the following code I am using the find method:
var rowConverter_P = function(d) {
return {
production_company: d.production_company,
Pass: parseInt(d.Pass),
Fail: parseInt(d.Fail)
};
}
d3.csv(production_dataset_url, rowConverter_P).then(function(data){
d3.selectAll("input").on("change", function(){
var paragraphID = d3.select(this).attr("id");
console.log("paragraph id", paragraphID); //this works
if($(this).is(":checked")) {
var new_data= data.find(d => d.production_company == paragraphID);
console.log("new data: ", new_data);}
}});
my Html code:
<div class="dropdown-menu">
<button class="dropdown-item" type="button">
<input type="checkbox" id="Columbia Pictures" checked> Columbia Pictures
</button>
<button class="dropdown-item" type="button">
<input type="checkbox" id="Universal Pictures" checked> Universal Pictures
</button>
<button class="dropdown-item" type="button">
<input type="checkbox" id="Warner Bros." checked> Warner Bros.
</button>
</div>
The issue here is that I get the variable new_data = Undefined. I thought that maybe because I am comparing two values with different data types, I converted the variable paragraphID to a string as I parse production_company as a string earlier, but still, it is undefined. what am I missing here?