Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

javascript find smallest number in an array

const arr = [14, 58, 20, 77, 66, 82, 42, 67, 42, 4]
const min = Math.min(...arr)
console.log(min)
Comment

get largest number in array javascript

const array1 = [1, 3, 2];

Math.max(...array1);
// expected output: 3
Comment

find smallest number in array js

//Not using Math.min:
const min = function(numbers) {
  let smallestNum = numbers[0];
for(let i = 1; i < numbers.length; i++) {
    if(numbers[i] < smallestNum) {
      smallestNum = numbers[i];   
    }
  }
return smallestNum;
};
Comment

find the largest number in array javascript

const result = (data) => {
  let max = 0;
  for (let i = 0; i < data.length; i++) {
    if (data[i] > max) {
      max = data[i];
    }
  }
  console.log("===> :: max", max);
}

const inputData = [2, 3, 5, 4, 54, 69, 4, 44, 3, 6, 45, 6, 4, 6]
result(inputData);
Comment

Find smallest Number from array in javascript

function smallestElemnts(numbers) {
    var smallest = numbers[0];
    for (let i = 0; i < numbers.length; i++) {
        var elements = numbers[i];
        if (elements < smallest) {
            smallest = elements;
        }
    }
    return smallest;
}
const numbers = [2, 3, 4, 8, 5, 2, 4];
console.log(smallestElemnts(numbers));
//Output: 2
Comment

how to find the smallest two numbers in an array javascript

function sumTwoSmallestNumbers(numbers) {  
  numbers = numbers.sort((a, b) => {
    return a - b; });
};  //this will turn the numbers list into the 2 lowest numbers
Comment

find largest number from an array in JavaScript

const array = [3 , 6, 2, 56, 32, 5, 89, 32];
let largestNum= array[0];

for (let i=1; i<array.length; i++){
    if (array[i]>largestNum) {
        largestNum = array[i];
    }
};
console.log(largestNum);
Comment

js largest number in array

array.reduce((max,x) => max < x ? x : max);
Comment

javascript largest number in array

const max = arr => Math.max(...arr);
Comment

Get the Largest Element of an Array, array js

const getLargest = (arr) =>
  arr.reduce((largest, num) => Math.max(largest, num));
const arr = [13, 7, 11, 3, 9, 15, 17];
console.log(getLargest(arr)); // 17
Comment

largest and smallest number in an array 1-100 javascript

let numArray = [95, 1, 75, 7, 12, 50, 3, 88]
numArray.slice().sort(function(a, b) {
  return a - b
})
console.log('smallest: ' + numArray[0] + ', largest: ' + numArray[numArray.length - 1])
Comment

how to find smallest number in array js

Array.min = function( array ){
    return Math.min.apply( Math, array );
};
Comment

get smallest value in array js

var test=[1, 2, 4, 77, 80];
console.log("Smallest number in test: "+Math.floor(Math.min(test)));
Comment

function that search a biggest value in array javascript

function maisBaratosQue(valor, precos) {
   return precos.filter(p => p <= valor);
}
Comment

get largest no in the array javascript

//For Values
var arr =[1,10,3]
var min = Math.min.apply(null, arr),
    max = Math.max.apply(null, arr);

//For Objects
var arr = [{a: 1},{a: 10},{a: 3}]
var values = arr.map(val => val.a);
var max = Math.max.apply(null, values);
console.log(max)
Comment

Find largest number from array by function in javascript

function largestElements(numbers) {
    var largest = 0;
    for (let i = 0; i < numbers.length; i++) {
        var elements = numbers[i];
        if (elements > largest) {
            largest = elements;
        }
    }
    return largest;
}
const numbers = [2, 3, 4, 8, 5, 2, 4];
console.log(largestElements(numbers));
//Output: 8
Comment

find the largest array from an array in javascript

const numbers = [
  [1, 2, 3],
  [4, 5, 6],
  [7, 8, 9, 10, 11],
];

let largestArray = numbers[0].length;
for (let i = 1; i < numbers.length; i++) {
  if (numbers[i].length > largestArray) {
    largestArray = numbers[i];
    for (let j = 0; j < largestArray.length; j++) {
       console.log(numbers[i][j]);
    }
  }
}

//it will print 7, 8, 9, 10, 11 as these numbers are in largest array;
Comment

get biggest element in array javascript

// first of all, i write a forEach loop function

// raw fanction
function getArrayLargestElement(array) {
  let largestElement = "";
  array.forEach(largest);
  function largest(word) {
    if (word.length > largestElement.length) {
      largestElement = word;
    }
  }
  return largestElement;
}

const banglaGit = [
  "amader",
  "sonar",
  "bangladesh",
  "ami tomay",
  "onek ",
  "valo basi",
];

console.log(getArrayLargestElement(banglaGit));

// es6 arrow function

const getLargestArrowFunc = (array) => {
  let largest = "";
  array.forEach((word) => {
    if (word.length > largest.length) {
      largest = word;
    }
  });
  return largest;
};

console.log(
  getLargestArrowFunc(["hello", "world", "md yeamin", "i'm", "here"])
);
Comment

Get the Smallest Element of an Array, array js

const getSmallest = (arr) =>
  arr.reduce((smallest, num) => Math.min(smallest, num));
const arr = [13, 7, 11, 3, 9, 15, 17];
console.log(getSmallest(arr)); // 3
Comment

js get smallest value of array

Array.min = function( array ){
    return Math.min.apply( Math, array );
};
var minimum = Array.min(array);
Comment

PREVIOUS NEXT
Code Example
Javascript :: jq unique by object attribute in list 
Javascript :: hover inline css 
Javascript :: Caused by: PG::ConnectionBad: could not connect to server: No such file or directory Is the server running locally and accepting connections on Unix domain socket "/var/pgsql_socket/.s.PGSQL.5432"? postgres app 
Javascript :: sqlite get row id after insert nodejs 
Javascript :: guage chart highchart codepen 
Javascript :: how to parse arguments to a promise in javascript 
Javascript :: mongoose undo delete 
Javascript :: javascript hashmap equivalent 
Javascript :: array.includes is not a function react 
Javascript :: add google maps nuxt js 
Javascript :: limit ajax request 
Javascript :: javascript timer code 
Javascript :: 00979fb28f7cc517ff28c035bb8ef10698d0d991304e9901ba214ad0cada69ef:script- 
Javascript :: call function on scroll down javascript 
Javascript :: EventEmitter to emit a custom event 
Javascript :: nodejs how to beautify mysql arrays 
Javascript :: declerative and imperative program combine 
Javascript :: time date utils 
Javascript :: convert File to multer file js 
Javascript :: How to Use the Return Keyword in a Function 
Javascript :: get id from javascript function call 
Javascript :: Check If Key Exists For Object 
Javascript :: Prototype Constructor Will Be Class or Function 
Javascript :: how to iterate through linked list javascript 
Javascript :: Comparing mongoose _id and strings 
Javascript :: 404 error firebase react js 
Javascript :: Register Multiple Models In Admin 
Javascript :: onclick add and remove class using jquery 
Javascript :: cefsharp transparent background 
Javascript :: starting: intent error type 3 react-native 
ADD CONTENT
Topic
Content
Source link
Name
8+3 =