chaelgutierrez
chaelgutierrez

Reputation: 83

How to update specific property on array of object?

Say "I initialized an array with predefined values like this" in my controller

  data: A([
    {
      lat: 14.5619175,
      lng: 121.0197196,
      title: "Jazz Mall",
      open: false
    },
    {
      lat: 14.5660656,
      lng: 121.0295681,
      title: "Avalue Residences",
      open: false
    },
    {
      lat: 14.5661493,
      lng: 121.0282417,
      title: "Century City",
      open: false
    }
  ])

Now, How can I update values to something like

title: "Jazz Mall" to title: "Value has been change"

Upvotes: 1

Views: 34

Answers (1)

rinold simon
rinold simon

Reputation: 3052

If I understand the question correctly then just by changing the value of the first array object would do this,

data.forEach((d) => {
  if (d.title === "Jazz Mall") {
    d.title = "Value has been changed"
  }
})
console.log(data);

Using ember set method

set(this.get('data').objectAt(index), 'prop', value)

Upvotes: 1

Related Questions