I have two arrays:
1- inventory
that contains some elements
2- indices_dates
that contains the indices of the elements I want from inventory
.
Is there a simple way to create an array formed by the elements of inventory
if their index is contained into indices_dates
Example:
let inventory
let indices_dates
let final = []
inventory = [25, 35, 40, 20, 15, 17]
indices_dates = [0, 2, 3, 5]
---Some Code To Get Final Array---
The output I would like:
final = [25, 40, 20, 17]
I did the following:
let inventory
let indices_dates
let final = []
let i
inventory = [25, 35, 40, 20, 15, 17]
indices_dates = [0, 2, 3, 5]
for (i in indices_dates) {
final.push(inventory[indices_dates[i]])
}
But I am wondering if there is another, more direct way to achieve it.