Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Object Oriented Programming Articles
Page 173 of 589
Display the Asian and American Date Time with Date Object in JavaScript
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 MoreHow can I filter JSON data with multiple objects?
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 MoreMulti-selection of Checkboxes on button click in jQuery?
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 MoreHow to avoid inserting NULL values to a table with JavaScript?
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 MoreHow to move all capital letters to the beginning of the string in JavaScript?
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 MoreCheck if value of an object of certain class has been altered in JavaScript and update another value based on it?
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 MoreCheck for illegal number with isNaN() in JavaScript
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 MoreImplement Onclick in JavaScript and allow web browser to go back to previous page?
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 MoreHow to check for 'undefined' or 'null' in a JavaScript array and display only non-null values?
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 MoreHow do I trigger a function when the time reaches a specific time in JavaScript?
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