B
B
Boris Manzhela2018-04-12 17:44:35
JavaScript
Boris Manzhela, 2018-04-12 17:44:35

How to get the index of an array inside an array in Vue.js?

How to get the INDEX_ARray inside an array without the this keyword , because in Vue.js does it point to the parent?
Thank you!

var my_array = [{
    data: 123,
    operation:  my_array[ИНДЕКС_МАССИВА].data * 5
}, {
    data: 845,
    operation:  my_array[ИНДЕКС_МАССИВА].data * 2
}, {
    data: 'dsdsd',
    operation:  my_array[ИНДЕКС_МАССИВА] + 'qwqwqw'
}]

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
alexalexes, 2018-04-12
@alexalexes

When you start sorting through the array, then you will get the indices.
https://learn.javascript.ru/array-iteration
You have a task of knowledge of bare JavaScript.

var my_array =
[
  {
    data: 123
  },
  {
    data: 845
  },
  {
    data: 'dsdsd'
  }
];

my_array.forEach(function(item, i, arr)
{
  switch(i)
  {
    case 0:
      item.operation = item.data * 5;
      break;
    case 1:
      item.operation = item.data * 2;
      break;    
    default:
      item.operation = item.data + 'qwqwqw';
  } 
});

PS: Read about how to put inside foreach this here .

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question