• 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-673fbd850d56b475405033/] [crayon-673fbd850d571520600702/] 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-673fbd850d572623125093/] [crayon-673fbd850d573464054849/] 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-673fbd850da51631853315/] [crayon-673fbd850da55385422155/] 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-673fbd850e995400939262/] [crayon-673fbd850e999102173886/] 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-673fbd850f2e1225530326/] [crayon-673fbd850f2e5640778151/] […]

  • 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-673fbd850f74b293974381/] Output: [crayon-673fbd850f751598883740/] 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 […]