[英]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.