JavaScript Array count | Get the Array length example

Use length property to get Array count in JavaScript. A length property also used to iterated through by looking at the length property and Create empty array of fixed length, etc. Example count Array in JavaScript HTML example code:

Output: Q: How to count certain elements in Array? Answer: Let’s find how many 2s Read More…


Count duplicate elements in array JavaScript | Example code

You have to do some coding in loop to get the count of duplicate elements in array JavaScript. We will do code using the forEach and for loop. JavaScript count same elements in array Example HTML example code: Lengthy code: In this code elements will be fetch from array and will counted in for loop. Read More…


JavaScript length of number | HTML example code

First convert the number to string using toString() in built method. Then use length() method to get length of number in JavaScript.

JavaScript length of number Example Complete HTML example code: Note: This process will also work for Float Number and for Exponential number also.

Output: If you don’t want to use toString() Read More…


Get first n characters of string JavaScript | Example code

You can use substring or slice method to Get first n characters of string in JavaScript. Where n could be any number 1,2,3… so on. Get first n characters of string JavaScript Examples HTML examples code: Let’s get first 4 char from string in JS. Using substring() Method:

Using slice() Method:

Output: Result 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 split() method. It doesn’t change Read More…


Reverse a string in one line JavaScript | HTML example code

There is no single method to Reverse a string in one line JavaScript but you can arrange methods in a single line. Use split, reverse, and join method for it. Reverse a string in one line JavaScript Example HTML example code: crated a function for it you can use only return value code if want Read More…


Reverse string in JavaScript | Using for loop and inbuilt methods examples

There are serval ways to do Reverse string in JavaScript. The most common ways are using Using for Loop and built-in Methods (split, array revers and join). Reverse string in JavaScript Examples HTML examples: Using for Loop Inside function created empty “newString” variable. In for loop add last item first position in the new string, Read More…


Get the first character of string JavaScript | example code

The simplest way to get the first character of the given string in JavaScript is charAt method. This method returns the character at the specified index in a string. Another way is the substring method to extracts the characters from a string, between two specified indices. Get the first character of string JavaScript Examples HTML Read More…


JavaScript split a string at the index | Particular and nth position example

Use substring method to split a string at the index in JavaScript. You can also create function for it. JavaScript split the string at index Example code HTML example code: How do split a string at a particular index? e.g split string at index 10, making the string now equal to everything up to index Read More…


JavaScript get the first 3 characters of a string | HTML example code

Use slice method to get first 3 characters of a string in JavaScript. JavaScript get first 3 characters of string Example A slice(begin, end) method works on strings, as well as arrays. It returns a string representing the substring of the original string, from beginning to end (end not included) where to begin and to Read More…