JavaScript count Array elements | Example code

Use for loop to get count array elements in JavaScript. Let’s see HTML example code:- Count certain elements in Array Output: Use JavaScript array length property returns get count of total elements in the Array. Get number of elements in an array. Output: 8 Do comment if you have any doubts and suggestions on this Read More…


JavaScript count items in Array | Example code

Use Array length Property to count items in JavaScript Array. It’s return the number of elements in an array. Return the length of an array: Set the length of an array: HTML Example code: Output: Do comment if you have any doubts and suggestions on this JS Array topic. RohitDegree in Computer Science and Engineer: Read More…


JavaScript split a string into an Array | Example code

Use the split() method. When specifying an empty string as the separator, the split() method will return an array with one element per word. JavaScript split string into array Example code HTML example code: Split a string into an array of words or substring and returns the new array using the split() method. It doesn’t Read More…


JavaScript split a sentence into an array of words | Example code

Just use the split method to convert sentences into an array of words in JavaScript. You have to use a separator which uses to indicating where each split should occur. We will use a space separator, you can use a comma or another. JavaScript split a sentence into an array of words Example HTML example Read More…


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…


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…


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…