Found 8895 Articles for Front End Technology

How to count JavaScript array objects?

Shubham Vora
Updated on 31-Oct-2023 03:09:02

23K+ Views

In this tutorial, we will learn to count JavaScript array objects. The array is the data structure containing the strings, numbers, objects, etc., in JavaScript. The object is the one kind of entity that contains properties and methods related to it. We can access the object's properties and invoke the object method using the object's references. Generally, To find the array length, we can use the array.length() method and it returns the total number of elements that the array includes. But what if we need to count only object elements? Here, this tutorial has various approaches to counting the total ... Read More

How to clone a Date object in JavaScript?

Shubham Vora
Updated on 17-Aug-2022 08:07:27

2K+ Views

In this tutorial, we will learn to clone a Date object in JavaScript. We can create a new object of the Date class that contains the date and time according to the user’s requirement. Sometimes, it needs to copy the date, which means cloning it. In such cases, users can use the different approaches given below. Also, we will learn to set the new time and date in the cloned date in this tutorial. Clone a Date using the Date.getTime() Method Users can simply create the new object of the Date class and get the total number of milliseconds from ... Read More

How to add 10 seconds to a JavaScript date object?

Saurabh Jaiswal
Updated on 22-Aug-2022 08:08:54

4K+ Views

In this tutorial, we will learn how to add 10 seconds to a JavaScript Date object. Here we will discuss two methods which are following. Using the setSeconds( ) Method Using the getTime() Method Using the setSeconds() Method JavaScript date setSeconds() method sets the seconds for a specified date according to local time. This method takes two arguments, the first is the number of seconds between 0 to 59 and the second is the number of milliseconds between 0 to 999. If you do not specify the second parameter, the value returned from the getMilliseconds() method is used. ... Read More

How to compare two dates with JavaScript?

Shubham Vora
Updated on 17-Aug-2022 08:14:16

19K+ Views

In this tutorial, we will learn to compare two dates with JavaScript. The date is also one of the data types in JavaScript, and most developer works with it while developing applications. Let’s understand the need to compare the date with a real-life example. Most of you are using the internet data, and the company sends a message like “2 days left for your data pack validity.” Also, users can see the same notification in the application of network provides. This all happens due to the date comparison. Here, we have two various approaches to make a comparison between the ... Read More

How to add 2 hours to a JavaScript Date object?

Saurabh Jaiswal
Updated on 05-Oct-2023 00:58:04

25K+ Views

In this tutorial, we will learn how to add 2 Hours to a JavaScript Date object. Here we will discuss two methods which are following. Using the getTime() Method Using the setHours() Method Using the getTime( ) Method JavaScript date getTime() method returns the numeric value corresponding to the time for the specified date according to universal time. The value returned by the getTime() method is the number of milliseconds since 1 January 1970 at 00:00:00. Syntax Following the syntax for the getTime() method − Date.getTime() Approach To add 2 hours to the Date Object first, we ... Read More

How do you convert a JavaScript date to UTC?

Shubham Vora
Updated on 02-Aug-2022 09:41:10

12K+ Views

In this tutorial, we will learn to convert the date to UTC. The full form of the UTC is the universal time coordinate, and it is a standard time that is considerable in every country. Let’s understand the need to convert the date to UTC by example. You have created the chat application. Users from various countries are using your application. Suppose that one user is from the USA and another from India. Both have a different time zone. So, you can either show the user to message received or send time in the local time or the UTC. There ... Read More

How to add 30 minutes to a JavaScript Date object?

Saurabh Jaiswal
Updated on 22-Aug-2022 08:30:54

10K+ Views

In this tutorial, we will learn how to add 30 minutes to a JavaScript Date object. Here we will discuss two methods which are following. Using the setMinutes( ) Method Using the getTime() Method Using the setMinutes Method The setMinutes() function of the date object accepts an integer representing the Minutes and replaces the value of the Minutes in the current date with it. Syntax Date.setMinutes(min, sec, ms); Parameter min − An integer between 0 and 59, representing the minutes. sec − An integer between 0 and 59, representing the seconds. If you specify the sec ... Read More

How to get the only current year in JavaScript?

Priya Pallavi
Updated on 18-Jun-2020 09:24:47

2K+ Views

To get an only current year, use the JavaScript getFullYear() method. JavaScript date getFullYear() method returns the year of the specified date according to local time. The value returned by getFullYear() is an absolute number. For dates between the years 1000 and 9999, getFullYear() returns a four-digit number, for example, 2008.ExampleYou can try to run the following code to get a current year in JavaScript −Live Demo           JavaScript getFullYear Method                        var dt = new Date("December 30, 2017 23:15:00");          document.write("getFullYear() : " + dt.getFullYear() );           OutputgetFullYear() : 2017

How to get the day of the week in JavaScript?

Shubham Vora
Updated on 26-Aug-2022 13:14:12

2K+ Views

The most common techniques for getting a day of the week and the name of the day in JavaScript will be covered in this tutorial. It is important to remember that if you are working on a small project, starting to install packages for something basic may be difficult. Small apps should be developed using JavaScript's built-in techniques; dependencies should only be included when absolutely necessary. Following are the approaches to get the day of the week in JavaScript − Using the getDay() Method Using the toLocaleString() Method Using the getDay() Method Use the JavaScript getDay() method ... Read More

How to get the day of the month in JavaScript?

Shubham Vora
Updated on 26-Aug-2022 13:01:36

6K+ Views

In this tutorial, we will learn how to find out the day of the month using JavaScript. We'll go over the most popular methods which are used for obtaining the name of the month and day in JavaScript. It is important that starting to install packages for something basic may be frustrating if you are working on a tiny project. JavaScript's built-in methods should be used to implement small applications; dependencies should only be added when absolutely necessary Using the getDate() Method A built-in data type for working with dates and times is the Date object. The new Date ... Read More

Advertisements