

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Getting equal or greater than number from the list of numbers in JavaScript
We are required to write a JavaScript function that takes in an array of numbers as the first argument and a single number as the second argument. The function should return an array of all the elements from the input array that are greater than or equal to the number taken as the second argument.
Example
Following is the code −
const arr = [56, 34, 2, 7, 76, 4, 45, 3, 3, 34, 23, 2, 56, 5]; const threshold = 40; const findGreater = (arr, num) => { const res = []; for(let i = 0; i < arr.length; i++){ if(arr[i] < num){ continue; }; res.push(arr[i]); }; return res; }; console.log(findGreater(arr, threshold));
Output
This will produce the following output in console −
[ 56, 76, 45, 56 ]
- Related Questions & Answers
- How to get the smallest integer greater than or equal to a number in JavaScript?
- Select equal or nearest greater number from table in MySQL
- JavaScript: Finding nearest prime number greater or equal to sum of digits - JavaScript
- Python - Number of values greater than K in list
- Number of Sub-arrays of Size K and Average Greater than or Equal to Threshold in C++
- How to find numbers in an array that are greater than, less than, or equal to a value in java?
- Smallest prime number just greater than the specified number in JavaScript
- First element greater than or equal to X in prefix sum of N numbers using Binary Lifting in C++
- How to apply Greater Than or Equal operation on the elements of two series objects?
- Python Indices of numbers greater than K
- Python – Find the frequency of numbers greater than each element in a list
- Numbers smaller than the current number JavaScript
- Mask array elements greater than or equal to a given value in Numpy
- How to find the frequency of values greater than or equal to a certain value in R?
- Remove tuples from list of tuples if greater than n in Python
Advertisements