JavaScript: Remove specified elements from the left of a given array of elements
JavaScript fundamental (ES6 Syntax): Exercise-18 with Solution
Write a JavaScript program to remove specified elements from the left of a given array of elements.
Sample Solution:
JavaScript Code:
//#Source https://bit.ly/2neWfJ2
function remove_from_left(arr, n = 1){
return arr.slice(n);
}
console.log(remove_from_left([1, 2, 3]));
console.log(remove_from_left([1, 2, 3], 1));
console.log(remove_from_left([1, 2, 3], 2));
console.log(remove_from_left([1, 2, 3], 4));
Sample Output:
[2,3] [2,3] [3] []
Pictorial Presentation:
Flowchart:

Live Demo:
See the Pen javascript-basic-exercise-1-18 by w3resource (@w3resource) on CodePen.
Improve this sample solution and post your code through Disqus
Previous: Write a JavaScript program to split values of two given arrays into two groups. If an element in filter is truthy, the corresponding element in the collection belongs to the first group; otherwise, it belongs to the second group.
Next: Write a JavaScript program to remove specified elements from the right of a given array of elements.
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.
JavaScript: Tips of the Day
Chunks an array into n smaller arrays
Example:
const tips_chunkIntoN = (arr, n) => { const size = Math.ceil(arr.length / n); return Array.from({ length: n }, (v, i) => arr.slice(i * size, i * size + size) ); } console.log(tips_chunkIntoN([1, 2, 3, 4, 5, 6, 7,8], 4));
Output:
[[1,2],[3,4],[5,6],[7,8]]
- New Content published on w3resource:
- HTML-CSS Practical: Exercises, Practice, Solution
- Java Regular Expression: Exercises, Practice, Solution
- Scala Programming Exercises, Practice, Solution
- Python Itertools exercises
- Python Numpy exercises
- Python GeoPy Package exercises
- Python Pandas exercises
- Python nltk exercises
- Python BeautifulSoup exercises
- Form Template
- Composer - PHP Package Manager
- PHPUnit - PHP Testing
- Laravel - PHP Framework
- Angular - JavaScript Framework
- Vue - JavaScript Framework
- Jest - JavaScript Testing Framework