Web Development

There are many reasons to look for objects by the value of one of its properties. Here’s a way:

const PLANS = [
  {
    id: 1,
    title: "Personal",
    billing_cycle: "Annual",
    amount: "$15",
    best_value: true,
    features: [
      "Lorem Ipsum sit amet dolor benefit here 1",
      "Lorem Ipsum sit amet dolor benefit here 2",
      "Lorem Ipsum sit amet dolor benefit here 3",
      "Lorem Ipsum sit amet dolor benefit here 4"
    ]
  },
  {
    id: 2,
    title: "Enterprise",
    billing_cycle: "Annual",
    amount: "$50",
    best_value: false,
    features: [
      "Lorem Ipsum sit amet dolor benefit here 1",
      "Lorem Ipsum sit amet dolor benefit here 2",
      "Lorem Ipsum sit amet dolor benefit here 3"
    ]
  }
];

ES6

let id ='1';
let selectedPlan = PLANS.find(plan => plan.id ===6);

UnderscoreJS

Option #1

var selectedPlan = _.findWhere(PLANS, {id: 6});

Option #2

var selectedPlan = _.find(PLANS, function (obj) {
  return obj.id === 6;
});