简体   繁体   中英

how do i get the index of an object array

在此处输入图片说明 How do i access the index of an objects array. 在此处输入图片说明

I want to access the index of the items array in the form object

在此处输入图片说明

when i add a new item row. the items unit_price of the new row replace the already created rows.

this is where the problem is originating

 productSelected(product) {
     this.form.items['id'] = product.id;
     this.form.items['unit_price'] = product.price;
   }

i want assign the product.price to the form.items[index].unit_price

Your question is not clear.But my understanding i will post two type of answer:-

1) Get all the values from items array

   form.items.map((item)=> console.log(item));

2) Get Particuler index value:

   const findIndex = 0;
   form.items[findIndex];

What I understood is you want to fetch the index of item from the array, hope this help

form.items.forEach((item, index) => {
 console.log('item', item)
 console.log('index', index) // index of item
})

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM