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 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 ] Read More…


JavaScript map min value | Example code

To get min from map in JavaScript use sort method. Array values will be changed. JavaScript map min value Example HTML example code: First sorting an Array by value and then get zero index value. It will be min map value.

Output: Do comment if you have any doubts and suggestions on this JS 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 way to get min value form array. JavaScript find min value in an array of objects Examples HTML example codes:- Using apply() 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

PHP

Java

Matlab

C++

Ruby

jQuery

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 array to get 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 from Read More…


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

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