Javascript Articles - Page 590 of 671

How to apply a function simultaneously against two values of the array from left-to-right?

Manikanth Mani
Updated on 23-Jun-2020 08:28:25

196 Views

Use the reduce() method in JavaScript to apply a function simultaneously against two values of the array from left-to-right as to reduce it to a single value.The following are the parameters −callback − Function to execute on each value in the array.initialValue − Object to use as the first argument to the first call of the callback.ExampleYou can try to run the following code to learn how to work with reduce() method in JavaScript −           JavaScript Array reduce Method                        if (!Array.prototype.reduce) {     ... Read More

How to return the id of the first image in a document with JavaScript?

Kumar Varma
Updated on 23-Jun-2020 08:11:36

534 Views

To return the id of the first image, use the images property in JavaScript.ExampleYou can try to run the following code to return the id of the first image in a document −Live Demo                                            var val = document.images.length;          document.write("Number of images in the document: "+val);          document.write("The id of the first image: "+document.images[0].id);          

How to create a Date object and what all parameters it include?

Vrundesha Joshi
Updated on 02-Mar-2020 05:33:04

488 Views

The Date object is a datatype built into the JavaScript language. Date objects are created with the new Date( ) as shown below.Once a Date object is created, a number of methods allow you to operate on it. Most methods simply allow you to get and set the year, month, day, hour, minute, second, and millisecond fields of the object, using either local time or UTC (universal, or GMT) time.You can use any of the following syntaxes to create a Date object using Date() constructor −new Date( ) new Date(milliseconds) new Date(datestring) new Date(year, month, date[, hour, minute, second, millisecond ])The ... Read More

How to return the number of images in a document with JavaScript?

Samual Sam
Updated on 23-Jun-2020 08:12:05

1K+ Views

To return the number of images in a document, use the images property in JavaScript.ExampleYou can try to run the following code to get the count of images −Live Demo                                            var val = document.images.length;          document.write("Number of images in the document: "+val);          

How to return the time-zone offset in minutes for the current locale?

Anvi Jain
Updated on 23-Jun-2020 08:13:23

274 Views

JavaScript date getTimezoneOffset() method returns the time-zone offset in minutes for the current locale. The time-zone offset is the minutes in difference; the Greenwich Mean Time (GMT) is relative to your local time.ExampleYou can try to run the following code to return the time-one offset in minutes −           JavaScript getTimezoneOffset Method                        var dt = new Date();          var tz = dt.getTimezoneOffset();                    document.write("getTimezoneOffset() : " + tz );          

How to return the day of the week in the specified date according to universal time?

Akshaya Akki
Updated on 23-Jun-2020 08:13:52

145 Views

JavaScript date getUTCDay() method returns the day of the week in the specified date according to universal time. The value returned by getUTCDay() is an integer corresponding to the day of the week: 0 for Sunday, 1 for Monday, 2 for Tuesday, and so on.ExampleYou can try to run the following code to return the day of the week in the specified date −           JavaScript getUTCDay Method                        var dt = new Date( "January 15, 2018 20:15:20" );          document.write("getUTCDay() : " + dt.getUTCDay() );          

How is NaN converted to String in JavaScript?

Saurabh Jaiswal
Updated on 11-Aug-2022 12:17:10

3K+ Views

In this tutorial, we will learn how to convert NaN to String. NaN in JavaScript means Not a Number, whose type is Number but actually, it is not a number. To Convert, the NaN to a String we use Multiple methods some of which are discussed below. Using the String() Method Using the toString Method Using the || Operator Using the isNaN() Method Using Ternary Operator Using the String() Method The String() method in JavaScript is used to convert different values to String. To convert the NaN into String Just pass the NaN to this method. Here is ... Read More

Which event occurs in JavaScript when the dragged element is over the target?

Paul Richard
Updated on 23-Jun-2020 08:14:21

389 Views

The ondragover event triggers when the dragged element is over the drop target.ExampleYou can try to run the following code to learn how to implement ondragover event in JavaScript −Live Demo                    .drag {             float: left;             width: 100px;             height: 35px;             border: 2px dashed #876587;             margin: 15px;             padding: 10px;          }   ... Read More

What is the role of Browser Object Model (BOM) in JavaScript?

karthikeya Boyini
Updated on 23-Jun-2020 08:04:18

2K+ Views

The Browser Object Model (BOM) in JavaScript includes the properties and methods for JavaScript to interact with the web browser.BOM provides you with a window objects, for example, to show the width and height of the window. It also includes the window.screen object to show the width and height of the screen.ExampleYou can try to run the following code to learn how to get screen height and width −Live Demo                    document.write("Screen width: " + screen.width);          document.write("Screen width: " + screen.width);          

Set the day of the month for a specified date according to universal time?

Anjana
Updated on 23-Jun-2020 08:17:22

102 Views

JavaScript date setUTCDate() method sets the day of the month for a specified date according to universal time.The following is the parameter for setUTCDate(dayValue) −dayValue − An integer from 1 to 31, representing the day of the month.ExampleYou can try to run the following code to set the day of the month for a specified date −           JavaScript setUTCDate Method                        var dt = new Date( "Oct 15, 2017 23:30:00" );          dt.setUTCDate( 20 );                    document.write( dt );          

Advertisements