Object Oriented Programming Articles

Page 173 of 589

Display the Asian and American Date Time with Date Object in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 2K+ Views

JavaScript's Date object provides powerful timezone handling through the toLocaleString() method. You can display dates and times for different regions by specifying timezone identifiers. Syntax new Date().toLocaleString("en-US", {timeZone: "timezone_identifier"}); Parameters locale: Language and region format (e.g., "en-US", "en-GB") timeZone: IANA timezone identifier (e.g., "Asia/Kolkata", "America/New_York") Asian Time Zone Example // Display current time in Asian timezone (India) var asianDateTime = new Date().toLocaleString("en-US", { timeZone: "Asia/Kolkata" }); console.log("Asian Date Time (India):"); console.log(asianDateTime); // Convert to Date object for further processing var asianDateObject = new ...

Read More

How can I filter JSON data with multiple objects?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 17K+ Views

To filter JSON data with multiple objects, you can use the filter() method along with comparison operators. This allows you to extract specific objects based on criteria. Syntax array.filter(callback(element, index, array)) Example: Filter by Single Property const jsonObject = [ { studentId: 101, studentName: "David" }, { studentId: 102, ...

Read More

Multi-selection of Checkboxes on button click in jQuery?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 531 Views

Multi-selecting checkboxes is a common requirement in web forms. This can be achieved using jQuery to toggle all checkboxes with a single button click. Approach We'll use jQuery's prop() method to set the checked property of multiple checkboxes and toggleClass() to manage the button state. Example Multi-selection Checkboxes .changeColor { ...

Read More

How to avoid inserting NULL values to a table with JavaScript?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 660 Views

When building dynamic tables with JavaScript, it's important to validate user input and prevent NULL values from being inserted. This ensures data integrity and provides a better user experience. Understanding NULL Validation In JavaScript, we need to check for null, undefined, and empty strings before inserting values into a table. The basic condition structure is: while (!(variable1 == null || variable2 == null || variable3 == null)) { // Insert values only when none are null } Complete Example with Validation ...

Read More

How to move all capital letters to the beginning of the string in JavaScript?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 354 Views

To move all capital letters to the beginning of a string in JavaScript, we can use the sort() method with a regular expression to identify uppercase letters and rearrange them. Let's say we have the following string: my name is JOHN SMITH We'll use sort() along with the regular expression /[A-Z]/ to move all capital letters to the beginning of the string. Example var moveAllCapitalLettersAtTheBeginning = [...'my name is JOHN SMITH'] .sort((value1, value2) => /[A-Z]/.test(value1) ? /[A-Z]/.test(value2) ? 0 : -1 : 0).join(''); console.log("After moving all capital letters at the beginning:"); console.log(moveAllCapitalLettersAtTheBeginning); ...

Read More

Check if value of an object of certain class has been altered in JavaScript and update another value based on it?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 101 Views

In JavaScript, you can monitor changes to object properties and automatically update dependent values using getters and setters. This approach allows you to create reactive properties that respond when other properties change. Basic Property Monitoring with Getters The simplest approach uses getter methods to access current property values: class Student { constructor(studentMarks1, studentMarks2) { this.studentMarks1 = studentMarks1; this.studentMarks2 = studentMarks2; var self = this; ...

Read More

Check for illegal number with isNaN() in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 251 Views

In JavaScript, isNaN() function checks if a value is "Not a Number" (NaN). It's commonly used to validate numeric operations and detect illegal numbers in calculations. What is NaN? NaN stands for "Not a Number" and is returned when a mathematical operation fails or produces an undefined result, such as multiplying a string with a number. Syntax isNaN(value) Parameters value: The value to be tested. If not a number, JavaScript attempts to convert it before testing. Return Value Returns true if the value is NaN, false otherwise. Example: Detecting ...

Read More

Implement Onclick in JavaScript and allow web browser to go back to previous page?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 507 Views

JavaScript provides several methods to implement browser navigation functionality. The most common approach is using window.history.go(-1) with an onclick event to go back to the previous page. Syntax window.history.go(-1); // Go back one page window.history.back(); // Alternative method Using window.history.go(-1) The window.history.go(-1) method navigates back one page in the browser history: Go Back Example Current Page ...

Read More

How to check for 'undefined' or 'null' in a JavaScript array and display only non-null values?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 580 Views

In JavaScript, arrays can contain null or undefined values. To display only non-null and non-undefined values, you need to check each element before processing it. Sample Array with Mixed Values Let's start with an array containing valid strings, null, and undefined values: var firstName = ["John", null, "Mike", "David", "Bob", undefined]; console.log("Original array:", firstName); Original array: [ 'John', null, 'Mike', 'David', 'Bob', undefined ] Method 1: Using for Loop with != undefined This approach checks if each element is not undefined. Since null != undefined evaluates to true, this will ...

Read More

How do I trigger a function when the time reaches a specific time in JavaScript?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 3K+ Views

To trigger a function at a specific time in JavaScript, calculate the time difference between the current time and target time, then use setTimeout() with that delay. Basic Approach Extract the target time, calculate the milliseconds until that time, and schedule the function execution: Trigger Function at Specific Time Function will trigger at specified time Waiting for target time... ...

Read More
Showing 1721–1730 of 5,881 articles
« Prev 1 171 172 173 174 175 589 Next »
Advertisements