• Get String between two characters in JavaScript
    27 January

    Get String Between Two Characters in JavaScript

    💡TL;DR Use the substring() method to get String between two characters in JavaScript. [crayon-6768603db06e7757417516/] [crayon-6768603db06ee949098873/] 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-6768603db06f0234211553/] [crayon-6768603db06f1441218091/] The substring() method allows […]

  • 27 December

    Return 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-6768603db0c10845720828/] [crayon-6768603db0c15633577980/] We used the Boolean(), a built-in function in JavaScript, to check if a variable or […]

  • 23 December

    Create 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 December

    Get 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 December

    Update 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-6768603db11fd505665787/] [crayon-6768603db1200716087685/] Bracket notation in JavaScript is a way […]

  • 21 December

    Format 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 December

    Remove 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-6768603db1463094006970/] [crayon-6768603db1466166435620/] […]

  • 18 December

    Write 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-6768603db1568875030646/] Output: [crayon-6768603db156b531160372/] Using join() method To write array to CSV […]

  • 04 December

    Fill 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 […]