Found 448 Articles for Programming Scripts

Match any string containing one or more p's with JavaScript RegExp.

Moumita
Updated on 23-Jun-2020 08:26:48

146 Views

To match any string containing one or more p’s with JavaScript RegExp, use the p+ Quantifier.ExampleYou can try to run the following code to match any string containing one or more p’s. Here p is considered as a number of occurrences −           JavaScript Regular Expression                        var myStr = "Secure and Responsive!";          var reg = /s+/g;          var match = myStr.match(reg);                    document.write(match);          

What is the role of filter() method in JavaScript?

Ankitha Reddy
Updated on 30-Jul-2019 22:30:21

200 Views

JavaScript array filter() method creates a new array with all elements that pass the test implemented by the provided function. The following are the parameters − callback − Function to test each element of the array. thisObject − Object to use as this when executing callback. You can try to run the following code to learn how to work with filter() method in JavaScript − Example Live Demo JavaScript Array filter Method ... Read More

How to represent the source code of an object with JavaScript Arrays?

Govinda Sai
Updated on 23-Jun-2020 08:28:59

161 Views

JavaScript array toSource() method returns a string representing the source code of the array. This method is supported by Mozilla.ExampleYou can try to run the following code to learn how to represent the source code of an object with JavaScript Arrays −           JavaScript Array toSource Method                        var arr = new Array("football", "baseball", "volleyball", "cricket");                  var str = arr.toSource();          document.write("Returned string is : " + str );          

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

127 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 create a Date object and what all parameters it include?

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

414 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 time-zone offset in minutes for the current locale?

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

214 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

72 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() );          

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

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

51 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 );          

Set the full year for a specified date according to universal time.

Ramu Prasad
Updated on 23-Jun-2020 08:16:39

66 Views

JavaScript date setUTCFullYear() method sets the full year for a specified date according to universal time.The following are the parameters for setUTCFullYear(yearValue[, monthValue[, dayValue]]) −yearValue − An integer specifying the numeric value of the year, for example, 2008.monthValue − An integer between 0 and 11 representing the months January through December.dayValue − An integer between 1 and 31 representing the day of the month. If you specify the dayValue parameter, you must also specify the monthValue.ExampleYou can try to run the following code to set the full year for a specified date according to universal time −       ... Read More

Set the hour for a specified date according to universal time?

Jennifer Nicholas
Updated on 23-Jun-2020 08:15:29

57 Views

JavaScript date setUTCHours() method sets the hour for a specified date according to local time. The following is the parameter for setUTCHours(hoursValue[, minutesValue[, secondsValue[, msValue]]]) −hoursValue − An integer between 0 and 23, representing the hour.minutesValue − An integer between 0 and 59, representing the minutes.secondsValue − An integer between 0 and 59, representing the seconds. If you specify the secondsValue parameter, you must also specify the minutesValue.msValue − A number between 0 and 999, representing the milliseconds. If you specify the msValue parameter, you must also specify the minutesValue and secondsValue.ExampleYou can try to run the following code to ... Read More

Advertisements