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 491 of 534
How to read data from *.CSV file using JavaScript?
In this article, we are going to learn how to read data from *.CSV file using JavaScript. To convert or parse CSV data into an array, we need JavaScript's FileReader class, which contains a method called readAsText() that will read a CSV file content and parse the results as string text. If we have the string, we can create a custom function to turn the string into an array. To read a CSV file, first we need to accept the file. Now let's see how to accept the csv file from browser using HTML elements. ...
Read MoreHow to import local json file data to my JavaScript variable?
When working with local JSON files in JavaScript, you need to import the data into your JavaScript variables. This article demonstrates how to load JSON data from a local file using different methods depending on your environment. Let's say we have an employees.json file in our project directory: Sample JSON File employees.json { "Employees": [ { "userId": "ravjy", "jobTitleName": "Developer", "firstName": "Ran", "lastName": "Vijay", ...
Read MoreHow to change the font color of a text using JavaScript?
This tutorial teaches us to change the font color of text using JavaScript. While working with JavaScript and developing the frontend of an application, you may need to change the font color of text when an event occurs. For example, if you have an application that can turn a device on or off with a button, you might want the button text to be green when the device is on and red when it's off. JavaScript provides several methods to accomplish this dynamic color changing. Using the style Property The most common approach is to access an ...
Read MoreHow to display the selected option in a dropdown list with JavaScript?
In this tutorial, we will learn how to display the selected option in a dropdown list with JavaScript. A dropdown list is a switchable menu that enables users to select one item from various options. It's created using the tag and is commonly used in forms to gather user input. The DOM API functions getElementById() and querySelector() can be used to access a element and retrieve its selected value. Let's explore the different methods to display the selected option. Using selectedIndex Property The selectedIndex property returns the index of the currently selected option in ...
Read MoreHow to get first and last date of the current month with JavaScript?
In this tutorial, we will look at how to get the first and last date of the current month using JavaScript. Working with dates is common in web development, especially when building calendars, date pickers, or time-based features. JavaScript provides built-in methods to handle dates, and there are also external libraries that make date manipulation easier. Following are the approaches to get the first and last date of the month using JavaScript − Using a Date Object Using the Moment.js Library Using a Date Object JavaScript's built-in ...
Read MoreHow to pass an object as a parameter in JavaScript function?
In this tutorial, we will learn how to pass an object as a parameter in a JavaScript function. One of JavaScript's data types is represented by the Object type. It is used to store keyed collections as well as more complex entities. The Object() constructor or the object initializer / literal syntax can be used to create objects. Almost all JavaScript objects are instances of Object; a typical object inherits properties (including methods) from Object.prototype, though these properties may be shadowed (a.k.a. overridden). Following are the methods used to pass an object as a parameter in a ...
Read MoreHow to add background music to your web page?
To add background music on a web page, you can use the element or the legacy tag. The modern approach uses HTML5's element with the autoplay attribute to start music automatically when the page loads. For background music, set the audio player to be hidden by using CSS or by omitting controls. The loop attribute makes the audio repeat continuously. Always upload your music file to the server and reference it in the src attribute. Method 1: Using HTML5 Audio Element (Recommended) The element is the modern standard for embedding audio content: ...
Read MoreHow to compare two objects in JavaScript?
Objects in JavaScript are entities that consist of properties and types. For example, a car object might have properties like color, price, height, and width. const car = { color: 'Black', price: 2500000, height: '6 feet', width: '5 feet' } The equality operator (===) verifies whether two operands are equal and returns a Boolean value. However, it cannot directly compare objects because objects are reference types. document.write('tutorix' === 'tutorix' ...
Read MoreEnter key press event in JavaScript?
The Enter key press event in JavaScript allows you to detect when users press the Enter key (keycode 13) and execute specific functions. This is commonly used for form submissions, search functionality, or triggering actions without clicking a button. Basic Syntax You can handle the Enter key using the onkeypress event handler: onkeypress="yourFunctionName(event)" The Enter key has a keycode of 13, which you can check using event.keyCode. Method 1: Using onkeypress Attribute Enter Key ...
Read MoreHow to subtract days from a date in JavaScript?
In JavaScript, you can subtract days from a date using built-in Date methods. The most common approaches are using setTime() with getTime() for millisecond-based calculation, or setDate() with getDate() for simpler day-based arithmetic. Following are the methods we can use to subtract days from a date in JavaScript: Using the setTime() and getTime() methods Using the setDate() and getDate() methods Using setTime() and getTime() Methods The setTime() method sets a date by milliseconds since ...
Read More