javascript
27 JanuaryGet String Between Two Characters in JavaScript
💡TL;DR Use the substring() method to get String between two characters in JavaScript. [crayon-6901231f929ce414168107/] [crayon-6901231f929de209778142/] Here, we got String between , and ! in above example. Using substring() Method Use the substring() method to extract a substring that is between two specific characters from the given string in JavaScript. [crayon-6901231f929e1445957943/] [crayon-6901231f929e3076967758/] The substring() method allows […]
27 DecemberReturn Boolean from Function in JavaScript
Using the Boolean() Function To get a Boolean from a function in JavaScript: Create a function which returns a Boolean value. Use the Boolean() function to get a Boolean value from the function created in the previous step. [crayon-6901231f94beb329690827/] [crayon-6901231f94bf8266770607/] We used the Boolean(), a built-in function in JavaScript, to check if a variable or […]
23 DecemberCreate Array from 1 to 100 in JavaScript
Use for Loop To create the array from 1 to 100 in JavaScript: Use a for loop that will iterate over a variable whose value starts from 1 and ends at 100 while the variable’s value is incremented by 1 in each iteration. Inside the for loop, use the push() method to insert a value […]
23 DecemberGet Index of Max Value in Array in JavaScript
Using indexOf() with Math.max() Method To get an index of the max value in a JavaScript array: Use the Math.max() function to find the maximum number from the given numbers. Here, we passed an array and used the spread operator (...) to expand the array into individual elements. Use the .indexOf() function to get the […]
22 DecemberUpdate Key with New Value in JavaScript
Using Bracket Notation We can use bracket notation to update the key with the new value in Python. Update Single Key with New Value To update a single key with a new value, use bracket notation to read it and update it with a new value. [crayon-6901231f969f9726454447/] [crayon-6901231f96a04961806934/] Bracket notation in JavaScript is a way […]
21 DecemberFormat Phone Number in JavaScript
Using match() Method We use the match() method to format a phone number in JavaScript. Format Without Country Code To format the phone number without country code: Use the replace() method with a regular expression /\D/g to remove non-numeric elements from the phone number. Use the match() method with a regular expression to match and […]
21 DecemberRemove Word from String in JavaScript
Using replace() Method We can use the replace() method to remove a word or words from a string in JavaScript. Remove a Single Occurrence of a Word To remove a single occurrence of a word from a string, use the replace() method to replace the word in the string with an empty string. [crayon-6901231f9a8a2806237511/] [crayon-6901231f9a8ae699930760/] […]
18 DecemberWrite Array to CSV in JavaScript
Using toString() method To write array to CSV in JavaScript: Declare an array with some elements in it. Use the toString() method. This method will convert the array into the CSV(Comma-Separated Value). Finally, console the value to see the result. Follow the below program: [crayon-6901231f9abca550972665/] Output: [crayon-6901231f9abd1763270587/] Using join() method To write array to CSV […]
04 DecemberFill Array with Random Numbers in JavaScript
Using Array.from() and Math.random() method To fill array with random numbers in JavaScript: Use Math.random() to get random numbers between 0 to 1. Use array.from() with length with desired length and mapping function as () => Math.random() * 20. This mapping function will be executed for every element in the array. Let’s say we want […]
- 1
- 2
- 3
- …
- 5
- Nextkeyboard_arrow_right