![](/img/trans.png)
[英]Javascript: How do I get the index of a certain order of values in an array?
[英]Javascript: How to get values of an array at certain index positions
我有一個值數組
arr = ["a","b","c","d"]
我還有另一個索引數組
indexes = [0,2]
在這些索引處獲取數組值的最佳方法是什么?
如果我將該方法應用於上述值
它應該返回
["a","c"]
使用Array.map
:
arr = ["a","b","c","d"] indexes = [0,2] const res = indexes.map(e => arr[e]) console.log(res)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.