Here is a JavaScript object that I have:
var data =
{
"type": [
"car",
"bike"
],
"wheels": [
"4",
"2"
],
"open": [
"Jan",
"Jan"
],
"wheel_press": [
"35",
"19"
],
"max-weight": [
"4000",
"8"
],
"transition_plan": [
"",
null
],
"number_of_occurence": [
5696,
976
],
"model": [
"sedan",
"street"
}
I am trying to filter the object based on a specific key to get only the corresponding values for that key. Unfortunately, I haven't been able to find a similar question on StackOverflow.
I attempted to use this code snippet:
data.filter(type === 'car')
However, I encountered the following error:
.filter is not a function
The expected output should be as follows: If I filter on type === 'car', it should only display:
{
"type": [
"car"
],
"wheels": [
"4"
],
"open": [
"Jan"
],
"wheel_press": [
"35"
],
"max-weight": [
"4000"
],
"transition_plan": [
""
],
"number_of_occurence": [
5696
],
"model": [
"sedan"
}