How to remove all the elements after a particular index in ruby?

How to remove all the elements after a particular index in ruby?

n = 2

n = 2

arr = %w(10 20 30 40 50)

arr.delete_if {|num| arr.index(num) > n }

This is a way to remove all the array elements after n index.

Is there any other way to remove all the elements from an array without actually iterating over and comparing the condition.

Angular 9 Tutorial: Learn to Build a CRUD Angular App Quickly

What's new in Bootstrap 5 and when Bootstrap 5 release date?

Brave, Chrome, Firefox, Opera or Edge: Which is Better and Faster?

How to Build Progressive Web Apps (PWA) using Angular 9

What is new features in Javascript ES2020 ECMAScript 2020

Ruby on Rails vs PHP

Understanding the pros and cons of Ruby on Rails versus PHP is important when deciding how to create your business-critical applications.