Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

use spread operator in max method javascript

// Inbuilt method Math.max() is the most common method used to find a maximum value in an array.
//Every value of an array is sent into the Math function

var array = [1,2,3];
      var Max1 = Math.max(array);
      var Max2 = Math.max(array[1],array[1],array[2]) ;
      document.write(Max1);
      document.write(Max2);

//Output :
//NaN
//3

//it works similar if we use spread operator we don't have to pass each value

var array = [1,2,3];
      var Max1 = Math.max(array);
      var Max2 = Math.max(...array) ;
      document.write(Max1);
      document.write(Max2);

//Output :
//NaN
//3


//spread operator (...) is used instead of sending each value into math function. 
Comment

PREVIOUS NEXT
Code Example
Javascript :: express get, post, delete, put template 
Javascript :: javascript variable scope in if statement 
Javascript :: react : calling APIs after render w error message 
Javascript :: how to validate date in react js 
Javascript :: Prevent HTTP Parameter Polution in NodeJS 
Javascript :: how to write code for browser back button in javascript 
Javascript :: Simple Backbone Example 
Javascript :: file path to blob javascript 
Javascript :: counter example using classes react without jsx 
Javascript :: How to Check if an Item is in an Array in JavaScript Using Array.includes() Starting From a Specified Index 
Javascript :: how to get event from iframe 
Javascript :: set to array js 
Javascript :: break and continue in javascript 
Javascript :: javascript add button 
Javascript :: new react 
Javascript :: how to convert string into int js 
Javascript :: react how to get checkbox value on click 
Javascript :: javascript add css class 
Javascript :: react upload image 
Javascript :: Manage selection fabric js 
Javascript :: intersection array of object javascript 
Javascript :: findPotentialLikes javascript 
Javascript :: JavaScript Methods and this Keyword 
Javascript :: javascript WeakMaps Are Not iterable 
Javascript :: electron webcontent send data into react not working 
Javascript :: get max type value in solidity 
Javascript :: bootstrap on tabs change 
Javascript :: change origin phaser 
Javascript :: phaser animation repeat event 
Javascript :: apply multiple style objects in react js 
ADD CONTENT
Topic
Content
Source link
Name
7+6 =