1

I have an array of values

arr = ["a","b","c","d"]

and I have another array of indexes

indexes = [0,2]

What is the best way to get the values of the array at these indexes ?

If I apply the method to the values above

it should return

["a","c"]

1 Answer 1

2

Use Array.map:

arr = ["a","b","c","d"]

indexes = [0,2]

const res = indexes.map(e => arr[e])

console.log(res)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.