JS get a random element from the Array | Example code

You can get a random element from the Array in JS by using Math.random() function to get the random number then Multiply it by the array length. After it, you will get numbers between zero to array length. Last use Math.floor() to get the index number from 0 to arrayLength-1. JS get a random element Read More…


Get random element from array JavaScript | Example code

Use Math.random * the length of the array, rounded down, as an index into the array to Get random element from array JavaScript. How to get a random element from array JavaScript Example HTML example code:- Get Random element form string array in JavaScript. Output: You output may be not same because this code get Read More…


JavaScript map max value | Example code

Use spread the values() into Math.max to get max map in JavaScript. JavaScript map max value Example HTML example code: Use spread the values() into Math.max: Output: Another Example If you need both the key and value, then use reduce() using the entries() method for the map: Output: Array [ “c”, 6 ] Q: How Read More…



How to get second smallest number in array JavaScript | Example code

Do sorting an Array in ascending order and get 2nd number is one way. Other ways are to get the second smallest number from array JavaScript is traversing the array twice or traversing the array and store it as the smallest element. get second smallest number in array JavaScript Example HTML example code: Sorting the Read More…


JavaScript array min value | Example code

Use Math.min() function to get the minimum valued number passed into it, or NaN if any parameter isn’t a number and can’t be converted into one. Buy functions min accept only number arguments. You have to use spread operator (…), apply() or reduce() with math. JavaScript array min value Example HTML example code: Since Math.min() Read More…


JavaScript find min value in an array of objects | Example code

Use JavaScript reduce() or Math method to get the min value in an array of objects. Using the Math functions with the spread operator (…) and sorting the array numerically with .sort() is a way to get the min value-form an array. JavaScript find min value in an array of objects Examples HTML example codes:- Read More…


Hello World in different programming languages | Codes

“Hello world” is the basic and simplest program possible in almost all computer languages. Every programmer writes it. Here are a quick compare syntax differences between various programming languages. Hello world in different programming languages slides: Codes are below image slide. R cat(‘Hello, world! ‘) PHP Java class HelloWorld { public static void main(String[] args) Read More…


Find the second smallest number in array JavaScript | Example code

If performance doesn’t bother you then simply sort the array and get the 1 index value of the array to get the second smallest number in array JavaScript. Find the second smallest number in array JavaScript Example HTML example code: Sort method will update existing array in increasing order. Output: Note: Array index is start Read More…


Find the smallest number in array JavaScript for loop | Example code

Finding the smallest value in Array is easy to use for loop statements. You need to first traversal the array element and store it to a new array (smallest_value_array). Compare the existing array value with a new one before you store it Find the smallest number in array JavaScript for loop Example HTML example code Read More…