I have an array containing two plan objects:
JavaScript
x
13
13
1
[ { "id": "price_aehdw424i7rxyeqiquedwuy",
2
"name": "Monthly Plan",
3
"price": 2900,
4
"interval": "month",
5
"currency": "usd",
6
},
7
{ "id": "price_46r34dgqn4d7w4fdw3476r323",
8
"name": "Yearly Plan",
9
"price": 29900,
10
"interval": "year",
11
"currency": "usd",
12
} ]
13
What I am trying to do is use a value (customerPlanId) to find the correct plan by matching it to the plan.id and then just return the correct plan, like below:
JavaScript
1
7
1
{ "id": "price_aehdw424i7rxyeqiquedwuy",
2
"name": "Monthly Plan",
3
"price": 2900,
4
"interval": "month",
5
"currency": "usd",
6
}
7
I know I can map through the plans and filter for the correct plan, but then how can I return the correct plan object on its own?
Advertisement
Answer
Solution
You could use the “Array.find” method
Example