Struggling with processing a JSON response object from an API call using .map()
and .filter()
. The structure of the data is a bit complex, making it difficult to pinpoint which object to operate on for my desired outcome.
.then(response => {
console.log(response); //refer below for data structure
var dataSourceInfo = response.data.included.filter(
element => element.type === "DataSource"
);
var dataSourceName = dataSourceInfo.map(function(included) {
return included["name"];
});
console.log(dataSourceName);
I'm trying to filter through response.data.included
to locate an element by type. Then, I want to map over the filtered result to create a new sorted array. Within one of the included
arrays, there exists a specific identifying type
called DataSource
, like this:
included: [
{
id: "2147483604",
type: "DataSource",
name: "Some DataSource"
},
After logging the dataSourceName
, I noticed that only one expected name appears in the array, and it's solely from the first array. It seems like the mapping process isn't reaching the second data.data
. Any suggestions on how I can display both names within the filtered array?
Edit: accurate response object is available in the codesandbox