Javascript Articles

Page 358 of 534

How to convert string type value to array type in JavaScript?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 445 Views

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 More

Is there any way to embed a PDF file into an HTML5 page?

Lakshmi Srinivas
Lakshmi Srinivas
Updated on 15-Mar-2026 779 Views

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 More

How to format JSON string in JavaScript?

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

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 More

Autocomplete text input for HTML5?

George John
George John
Updated on 15-Mar-2026 503 Views

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 More

How to subtract date from today's date in JavaScript?

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

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 More

Make HTML5 Canvas fill the whole page

Chandu yadav
Chandu yadav
Updated on 15-Mar-2026 3K+ Views

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 More

JavaScript Check for case insensitive values?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 316 Views

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 More

IE supports the HTML5 File API

Daniol Thomas
Daniol Thomas
Updated on 15-Mar-2026 195 Views

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 More

Split Space Delimited String and Trim Extra Commas and Spaces in JavaScript?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 447 Views

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 More

How to avoid repeat reloading of HTML video on the same page?

Nancy Den
Nancy Den
Updated on 15-Mar-2026 910 Views

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
Showing 3571–3580 of 5,340 articles
« Prev 1 356 357 358 359 360 534 Next »
Advertisements