Javascript Articles

Page 349 of 534

Add two consecutive elements from the original array and display the result in a new array with JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 379 Views

We are required to write a JavaScript function that takes in an array of Numbers and returns a new array with elements as the sum of two consecutive elements from the original array. For example, if the input array is: const arrayOne = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]; Then the output should be: const newArrayOne = [1, 5, 9, 13, 17] Let's write the code for this function: Example const arrayOne = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]; ...

Read More

Play local (hard-drive) video file with HTML5 video tag?

George John
George John
Updated on 15-Mar-2026 1K+ Views

The HTML5 tag allows you to play local video files from the user's hard drive using JavaScript's File API and URL.createObjectURL() method. This technique works with MP4, WebM, and Ogg video formats. HTML Structure Create a file input and video element: Local Video Player Your browser does not support the video tag. ...

Read More

Play infinitely looping video on-load in HTML5

Arjun Thakur
Arjun Thakur
Updated on 15-Mar-2026 5K+ Views

HTML5 provides built-in support for playing videos that loop infinitely using the loop attribute. This is useful for background videos, animations, or promotional content that should continuously play. Basic Syntax The element supports three main video formats: MP4, WebM, and Ogg. To create an infinitely looping video, combine the autoplay and loop attributes: Your browser does not support the video element. Key Attributes autoplay: Starts the video automatically when the page loads loop: A boolean attribute that restarts ...

Read More

JavaScript Remove all '+' from array wherein every element is preceded by a + sign

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 207 Views

When working with arrays containing strings that start with a '+' sign, you can remove these characters using JavaScript's map() method combined with replace(). Problem Statement Let's say we have an array where every element is preceded by a '+' sign: var studentNames = [ '+John Smith', '+David Miller', '+Carol Taylor', '+John Doe', '+Adam Smith' ]; Using map() with replace() The map() method creates a new array by calling a function on each element. We use replace() to ...

Read More

AngularJS and HTML5 date input value - how to get Firefox to show a readable date value in a date input?

Ankith Reddy
Ankith Reddy
Updated on 15-Mar-2026 321 Views

The elements of type date allow users to enter dates using a text box or date picker. With the ng-model directive, you can bind AngularJS application data to HTML input controls. However, Firefox has limited support for type="date" and converts values to strings, which can cause display issues. Since you want the date to be a real Date object and not a string, we need to create additional variables and link them together using watchers. The Problem Firefox doesn't fully support HTML5 date inputs and may not display dates in a readable format. The browser treats ...

Read More

Extract the value of the to a variable using JavaScript?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 795 Views

To extract the value of the element to a variable using JavaScript, use the textContent property to get the text content from any HTML or SVG text element. Syntax var textValue = document.getElementById("elementId").textContent; Example Extract SVG Text Value This is the JavaScript Tutorial ...

Read More

Apple Touch icon for websites in HTML

karthikeya Boyini
karthikeya Boyini
Updated on 15-Mar-2026 2K+ Views

Apple Touch Icons are custom icons that appear when users add your website to their iPhone or iPad home screen. These icons replace the default website screenshot with a professional-looking app-style icon. Basic Apple Touch Icon To add a basic Apple Touch Icon, include this in your HTML section: This creates a bookmark icon when users tap the share button and select "Add to Home Screen" on iOS devices. Multiple Sizes for Different Devices Different Apple devices require different icon sizes. Use the sizes attribute to specify multiple icons: ...

Read More

How can we separate the special characters in JavaScript?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 359 Views

In JavaScript, you can separate special characters from text using the match() method with regular expressions. This technique splits strings into arrays containing both word characters and special characters as separate elements. Syntax arrayName.flatMap(item => item.match(/\w+|\W+/g)); The regular expression /\w+|\W+/g works as follows: \w+ matches one or more word characters (letters, digits, underscore) | acts as OR operator \W+ matches one or more non-word characters (special characters, spaces) g flag ensures global matching throughout the string Example: Separating Special Characters from Names Let's separate special characters from an array of ...

Read More

Zoom HTML5 Canvas to Mouse Cursor

Ankith Reddy
Ankith Reddy
Updated on 15-Mar-2026 1K+ Views

The HTML5 Canvas API provides powerful methods to zoom content toward a specific point, such as the mouse cursor. By default, the canvas scales from its origin at [0, 0], but you can change this behavior using coordinate transformations. Understanding Canvas Transformations The translate() method moves the canvas origin to a new position, while scale() resizes the drawing context. To zoom toward the mouse cursor, you need to combine these transformations in a specific sequence. The Zoom Algorithm To zoom toward a specific point (like mouse coordinates), follow these three steps: ctx.translate(pt.x, pt.y); ...

Read More

How can I cut a string after X characters in JavaScript?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 749 Views

To cut a string after X characters in JavaScript, you can use several methods. The most common approaches are substr(), substring(), and slice(). Using substr() Method The substr() method extracts a portion of a string, starting at a specified index and extending for a given number of characters. var myName = "JohnSmithMITUS"; console.log("The String = " + myName); var afterXCharacter = myName.substr(0, 9); console.log("After cutting the characters the string = " + afterXCharacter); The String = JohnSmithMITUS After cutting the characters the string = JohnSmith Using substring() Method The substring() ...

Read More
Showing 3481–3490 of 5,340 articles
« Prev 1 347 348 349 350 351 534 Next »
Advertisements