1

How can ı equalize my array ıd and my value ıd and access value.name I didn't do it

This is my code:

activity(val) {
    var act = this.items.map(function (val) {
        if (element.ActivityID== val) {
            return element.ActivityName
        }

        return act
});

1 Answer 1

1

Perhaps this?

activity (val) {
  const activity = this.items.find(item => item.ActivityID === val)

  return activity && activity.ActivityName
}

This just finds the item with the corresponding ActivityID and then returns its ActivityName.

Your original code contained several possible mistakes:

  1. Two different things called val.
  2. element doesn't appear to be defined.
  3. The return act was inside the map callback. The activity method itself wasn't returning anything.
  4. Not really clear why you were using map to find a single item. map is used to create a new array with the same length as the original array with each item in the new array determined by the equivalent item in the original array. It 'maps' the items of the input array to the items in the output array.
0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.