JavaScript: Extract out the values at the specified indexes from a specified array
JavaScript fundamental (ES6 Syntax): Exercise-10 with Solution
Extract Values by Indexes from Array
Write a JavaScript program to extract values at specified indexes from a specified array.
- Use Array.prototype.filter() and Array.prototype.includes() to pull out the values that are not needed.
- Set Array.prototype.length to mutate the passed in an array by resetting its length to 0.
- Use Array.prototype.push() to re-populate it with only the pulled values.
- Use Array.prototype.push() to keep track of pulled values.
Sample Solution:
JavaScript Code:
Output:
["b","d"] [5]
Visual Presentation:
Flowchart:

Live Demo:
For more Practice: Solve these Related Problems:
- Write a JavaScript program that extracts values from an array based on a list of given indexes.
- Write a JavaScript function that returns a new array containing elements at specified positions from an input array.
- Write a JavaScript program that validates index bounds and then extracts corresponding elements from an array.
Improve this sample solution and post your code through Disqus
Previous: Write a JavaScript program to combine the numbers of a given array into an array containing all combinations.
Next: Write a JavaScript program to generate a random hexadecimal color code.
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.