0

I have an array that contains integers:

var _ListsvotesArray = [600, 2000, 6000, 400,1000];

// declare number of voters and number of seats
var _NumOftotalVoters = 10000;
var _NumAssForRegion = 13;

//divide the two numbers
var Quotient = _NumOftotalVoters / _NumAssForRegion;

What I'm trying to achieve: I want for every item in the array, if the "_ListsvotesArray[i]" is less than the "Quotient", i would like to remove it from the array

So, Let's consider the quotient is equal to "700", the new array should be:

var _ListsvotesArray = [2000, 6000,1000];

So how could I achieve the result above using Javascript?

Any help would be appreciated.

Thank you.

  • From what I can tell you are just looking to filter an array, which already has an answer here: [How to filter an array with JavaScript](https://stackoverflow.com/questions/45916135/how-to-filter-an-array-in-javascript). Basically you'll leverage the [array `.filter()` method](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/filter). – Alexander Nied May 11 '22 at 17:45
  • var array = [1,2,3,4,5,6,7,8]; var new_array = array.filter(function(item) { return item > 5; }); console.log(new_array) – Muhammad Fazeel May 11 '22 at 17:52
  • Thank you man, I really appreciate it, your code worked as needed. – roberto hajj boutros May 11 '22 at 18:18

0 Answers0