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
Javascript Articles
Page 358 of 534
How to convert string type value to array type in JavaScript?
Converting strings to arrays in JavaScript can be done using different methods depending on the string format. Here are the most common approaches. Using JSON.parse() for JSON Strings When you have a JSON-formatted string, use JSON.parse() to convert it to an array: var customerDetails = '[{"name": "John", "countryName": "US"}, {"name": "David", "countryName": "AUS"}, {"name": "Bob", "countryName": "UK"}]'; console.log("Original string:", customerDetails); console.log("Type:", typeof customerDetails); var convertStringToArray = JSON.parse(customerDetails); console.log("After converting to array:"); console.log(convertStringToArray); console.log("Type:", typeof convertStringToArray); Original string: [{"name": "John", "countryName": "US"}, {"name": "David", "countryName": "AUS"}, {"name": "Bob", "countryName": "UK"}] Type: string ...
Read MoreIs there any way to embed a PDF file into an HTML5 page?
To embed a PDF file in an HTML5 page, you can use several methods. The most common approaches are using the element, element, or element. Using iframe Element (Most Common) The element is the most widely supported method for embedding PDFs: Embed PDF with iframe PDF Embedded with iframe Your browser does not support iframes. ...
Read MoreHow to format JSON string in JavaScript?
To format JSON string in JavaScript, use JSON.stringify() with spacing parameters. This method converts JavaScript objects to formatted JSON strings with proper indentation for better readability. Syntax JSON.stringify(value, replacer, space) Parameters value - The JavaScript object to convert replacer - Function or array to filter properties (use null for all properties) space - Number of spaces or string for indentation Example var details = { studentId: 101, studentFirstName: 'David', studentLastName: 'Miller', studentAge: 21, subjectDetails: { ...
Read MoreAutocomplete text input for HTML5?
Use the autocomplete attribute for autocomplete text input. The autocomplete attribute is used with form elements to set the autocomplete feature on or off. If the autocomplete feature is on, the browser will automatically show values based on what users entered before in the field. If the autocomplete feature is off, the browser won't automatically show values based on what users entered before in the field. Attribute Values The following are the attribute values: S. ...
Read MoreHow to subtract date from today's date in JavaScript?
To subtract dates in JavaScript, you can work with Date objects directly or extract specific components like day, month, or year. The most common approach is to subtract one Date object from another to get the difference in milliseconds. Syntax var dateDifference = date1 - date2; // Returns difference in milliseconds var daysDifference = Math.floor((date1 - date2) / (1000 * 60 * 60 * 24)); Example 1: Subtracting Full Dates var currentDate = new Date(); var pastDate = new Date("2024-01-01"); // Get difference in milliseconds var timeDifference = currentDate - pastDate; console.log("Difference ...
Read MoreMake HTML5 Canvas fill the whole page
To make an HTML5 canvas fill the entire browser viewport, you need to remove default margins/padding and set the canvas dimensions to 100% of the page. CSS Setup First, reset the default browser styles and set up the HTML structure: * { margin: 0; padding: 0; } body, html { height: 100%; overflow: hidden; /* Prevents scrollbars */ } #canvas { position: absolute; top: 0; left: 0; ...
Read MoreJavaScript Check for case insensitive values?
JavaScript provides several methods to check for case insensitive values. The most common approaches use toLowerCase(), toUpperCase(), or regular expressions. Using toLowerCase() Method Convert both values to lowercase before comparison: let name1 = "JOHN"; let name2 = "john"; console.log(name1.toLowerCase() === name2.toLowerCase()); // true console.log("Hello".toLowerCase() === "HELLO".toLowerCase()); // true true true Using Regular Expression Use the i flag for case insensitive matching: let allNames = ['john', 'John', 'JOHN']; let makeRegularExpression = new RegExp(allNames.join("|"), "i"); let hasValue = makeRegularExpression.test("JOHN"); console.log("Is Present=" + hasValue); // Direct regex approach let ...
Read MoreIE supports the HTML5 File API
Internet Explorer's support for the HTML5 File API varies by version. IE9 does not support the File API, but IE10 and later versions provide full support for file operations. File API Browser Support The File API allows web applications to read file contents and metadata. Here's the IE support timeline: IE9: No File API support IE10+: Full File API support including FileReader, File, and Blob objects Modern browsers: Complete support across Chrome, Firefox, Safari, and Edge Example: File Reading with File API This example ...
Read MoreSplit Space Delimited String and Trim Extra Commas and Spaces in JavaScript?
When working with strings that contain multiple commas and spaces, you can use regular expressions with split() and join() methods to clean them up effectively. The Problem Consider this messy string with multiple consecutive commas and spaces: var sentence = "My, , , , , , , Name, , , , is John ,, , Smith"; console.log("Original string:", sentence); Original string: My, , , , , , , Name, , , , is John ,, , Smith Solution: Using Regular Expression with split() and join() The split(/[\s, ]+/) method splits ...
Read MoreHow to avoid repeat reloading of HTML video on the same page?
Use preload="auto" to avoid repeat reloading of HTML video on the same page. The preload attribute controls how much video data the browser should load when the page loads. Preload Attribute Options The preload attribute has three possible values: auto - Browser loads the entire video when the page loads metadata - Browser loads only video metadata (duration, dimensions) none - Browser doesn't load any video data initially Example with preload="auto" ...
Read More