- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Found 9290 Articles for Object Oriented Programming
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
412 Views
Following is the code to create a URL object using JavaScript −Example Live Demo Document body { font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif; } .result { font-size: 18px; font-weight: 500; color: rebeccapurple; } Url object in JavaScript CLICK HERE Click on the above button to create and display a url object let resEle = document.querySelector(".result"); let url = new URL("https://google.com/image=23&size=440px"); document.querySelector(".Btn").addEventListener("click", () => { resEle.innerHTML += "url protocol = " + url.protocol + ""; resEle.innerHTML += "url host = " + url.host + ""; resEle.innerHTML += "url.pathname = " + url.pathname + ""; }); OutputThe above code will produce the following output −On clicking the ‘CLICK HERE’ button −
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
278 Views
Following is the code for flattening multi-dimensional arrays in JavaScript −Example Live Demo Document body { font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif; } .result, .sample { font-size: 20px; font-weight: 500; } Flattening multi-dimensional arrays in JavaScript [1,2,3,[4,5],[6,[7,8]]] After flat : CLICK HERE Click on the above button to flat the above array by depth 2 let resEle = document.querySelector(".result"); let sampleEle = document.querySelector(".sample"); let arr = [1, 2, 3, [4, 5], [6, [7, 8]]]; document.querySelector(".Btn").addEventListener("click", () => { let store = arr.flat(2); store.forEach((item, index) => { resEle.innerHTML += index + " : " + item + ""; }); }); OutputOn clicking the ‘CLICK HERE’ button
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
228 Views
Following is the code showing file and fileReader in JavaScript −Example Live Demo Document body { font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif; } .result, .sample { font-size: 18px; font-weight: 500; color: rebeccapurple; } .result { color: red; } File and FileReader in JavaScript Click on the above button to display file and its details let resEle = document.querySelector(".result"); let sampleEle = document.querySelector(".sample"); function ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
199 Views
There are three ways to access JavaScript properties −Using dot property access: object.propertyUsing square brackets notation: object[‘property’]Using object destructuring: let {property} = objectFollowing is the code for accessing JavaScript object properties −Example Live Demo Document body { font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif; } .result, .sample { font-size: 18px; font-weight: 500; color: blueviolet; } .sample { color: red; } Access JavaScript object properties {a:22, b:44} Access Click on the ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
13K+ Views
Following is the code to convert an image to blob using JavaScript −Example Live Demo Document body { font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif; } .result { font-size: 18px; font-weight: 500; color: rebeccapurple; } Convert an Image to blob using JavaScript Convert Click on the above button to convert the above image to blob let BtnEle = document.querySelector(".Btn"); let resEle = gdocument.querySelector(".result"); BtnEle.addEventListener("click", () => { ... Read More
![Nikitasha Shrivastava](https://www.tutorialspoint.com/assets/profiles/655298/profile/60_3988199-1684213136.jpeg)
3K+ Views
In this problem statement, our task is to calculate the median of an array with the help of Javascript functionalities. There are several ways that can be used to solve this task. One simple method to calculate median is using the built-in function of Javascript. Understanding the problem statement The problem statement is to write a function in Javascript that will help to calculate the median of a given array. For example, if we have an array of integers [1, 2, 3, 4, 5] so the median of this array is 3. Because 3 is the middle element of the ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
444 Views
Following is the code for calculating average of an array in JavaScript −Example Live Demo Document body { font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif; } .result, .sample { font-size: 18px; font-weight: 500; color: blueviolet; } .sample { color: red; } Calculating average of an array Check Click on the above button to see document state let resEle = document.querySelector(".result"); let BtnEle = document.querySelector(".Btn"); let sampleEle = document.querySelector(".sample"); let arr = [1, 2, 3, 4, 5, 11, 22]; sampleEle.innerHTML = arr; BtnEle.addEventListener("click", () => { let sum = 0; arr.forEach((item) => (sum += item)); resEle.innerHTML = "The average of the array = " + sum / arr.length; }); OutputOn clicking the ‘Calculate’ button −
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
512 Views
TextEncoder is used to convert a given string to utf-8 standard. It retunes an Uint8Array from the string.TextDecoder is used to covert a stream of bytes into a stream of code points. It can decode UTF-8 , ISO-8859-2, KOI8-R, GBK etc.Following is the code for TextDecoder and TextEncoder in JavaScript −Example Live Demo Document body { font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif; } .result, .sample { font-size: 18px; font-weight: 500; color: rebeccapurple; } .result { ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
142 Views
Following is the code to destructure function parameters in JavaScript −Example Live Demo Document body { font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif; } .sample, .result { font-size: 18px; font-weight: 500; color: red; } .result { color: rebeccapurple; } De structuring function parameters CLICK HERE Click on the above button to call a function and pass above object to it as argument let sampleEle = document.querySelector(".sample"); ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
171 Views
Exception can be rethrown after they have been caught by using the throw after catching the exception.Following is the code to re-throw errors in JavaScript −Example Live Demo Document body { font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif; } .result { font-size: 18px; font-weight: 500; color: rebeccapurple; } Re-throw errors in JavaScript CHECK Enter a number bigger than 40 to re throw error; let BtnEle = document.querySelector(".Btn"); let resEle = ... Read More