- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Found 8894 Articles for Front End Technology
2K+ Views
We could apply String split(), Array sort() and Array join() methods to write a function that returns a passed string with letters in alphabetical order in JavaScript. A JavaScript function is a block of code that is executed when it is invoked. A string is a sequence of characters. In JavaScript, strings are represented by the type String.Input string : tutorialspoint Output string: aiilnooprstttuStepsSplit the string into an array of characters using split() method.Apply the sort() method to sort the characters in alphabetical order.Finally, we use the join() method to join the characters back into a string.The Array.sort() method sorts the ... Read More
27K+ Views
In JavaScript, there are different ways to convert an array of strings to an array of numbers. The first way is to use the built-in parseInt() method, and the second way is to use a type conversion function, and the third one is to use the unary + operator.Using the parseInt() methodThe parseInt() method is a built-in function in JavaScript that takes a string as an argument and returns a number. This method can be used to convert an array of strings to an array of numbers.SyntaxThe syntax of the parseInt() method is as follows −parseInt(string, radix);ParametersString − The string ... Read More
2K+ Views
JavaScript provides two functions for dealing with encoded strings: escape() and unescape(). The escape() function is used to encode a string, making it safe for use in a URL. The unescape() function is used to decode an encoded string.The differencesThe main difference between the two functions is that escape() encodes characters that are not ASCII, while unescape() only decodes those characters. This means that if you use escape() on a string that only contains ASCII characters, the result will be the same as the input string. However, if you use unescape() on a string that contains non-ASCII characters, the result ... Read More
6K+ Views
In JavaScript, there are two main ways that a variable can be "undefined". The first is when you declare a variable without giving it a value. The second is when you try to access a variable that does not exist.Undefined in JavaScript When a variable is declared without a value, it is automatically given the value of "undefined". This can happen if you forget to assign a value to a variable, or if you intentionally do not assign a value (For example, if you are waiting for user input).If you try to access a variable that does not exist, you will ... Read More
40K+ Views
JavaScript provides several ways to loop through arrays and objects. The most common way is the for loop, which is used to iterate through the elements of an array or object. However, there are other ways to loop through arrays and objects, such as the forEach() and map() methods.The forEach() MethodThe forEach() method is used to loop through each element of an array or object. The forEach() method takes a callback function as an argument. The callback function is invoked for each element of the array or object.The forEach() method is similar to the for loop, but it does not ... Read More
426 Views
In JavaScript, We can use the reduce() method to apply a function against an accumulator and each key of an object (from left to right).The reduce() method is called on a given array and takes in a callback function as its first argument. Please refer to Array reduce() for more details. Let’s look at the syntax of this method.Syntaxarray array.reduce(callback[, initialValue]);Parameterscallback − Function to execute on each value in the array.initialValue − Object to use as the first argument to the first call of the callback.The callback function is passed with four argumentsThe first argument is the accumulator, which is ... Read More
388 Views
In this tutorial, we'll be discussing how to get the sum of the powers of all the numbers from start to end in JavaScript. We'll be using the built-in Math.pow() method to calculate the powers and the Array reduce() method to sum up the values.Using the Math.pow() methodThe Math.pow() method allows us to calculate the power of a number. We can use this method to calculate the powers of all the numbers from start to end.SyntaxMath.pow(base, exponent) ;ParametersBase − The base number.Exponents − The exponent to which to raise the base.ExampleFor example, if we want to get the sum of ... Read More
882 Views
In JavaScript, there is a method called "Promise.all" that allows you to run an array of promises in parallel. However, sometimes you may want to run your promises in series instead. This can be useful if you want to make sure that each promise is executed one after the other, or if you need to use the result of one promise in the execution of the next promise.There are a few different ways that you can run an array of promises in series in JavaScript. In this article, we'll take a look at a few of them.Promise.prototype.then()One way to run ... Read More
3K+ Views
In JavaScript, there are often times when we need to find the first non-null/undefined argument in a function. This can be a tricky task, but luckily there are a few methods that can help us accomplish thisUsing Array.prototype.find()One method that can be used to get the first non-null/undefined argument in JavaScript is the Array.prototype.find() method. This method returns the value of the first element in an array that passes a given test. In our case, we can use this method to find the first non-null/undefined argument by passing a test that checks if the argument is not null/undefined.ExampleIn the example ... Read More
16K+ Views
When building web applications, there are often times when you need to dynamically generate HTML on the client-side. This can be done using JavaScript, and there are different ways to go about it. In this article, we'll show you how to return HTML or build HTML using JavaScript.Returning HTML from a functionOne way to dynamically generate HTML is to return a string of HTML from a function. For example, let's say we have a function that generates a list item −function generateListItem(text) { return '' + text + ''; }We can then use this function to generate HTML −function ... Read More