- 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 9315 Articles for Object Oriented Programming
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
329 Views
The get keyword can be used as a getter function like C#, Java and other technologies.We set a function with get like the following in a class −class Employee { constructor(name) { this.name = name; } get fullName() { return this.name; } }ExampleFollowing is the code displaying an example of get −class Employee { constructor(name) { this.name = name; } get fullName() { return this.name; } } var employeeObject = new Employee("David Miller"); console.log(employeeObject.fullName);To run the above program, you need to use ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
296 Views
We are required to write a JavaScript function that takes in two 2-D arrays of numbers and returns their matrix multiplication result.Let’s say the following are our two matrices −// 5 x 4 let a = [ [1, 2, 3, 1], [4, 5, 6, 1], [7, 8, 9, 1], [1, 1, 1, 1], [5, 7, 2, 6] ]; // 4 x 6 let b = [ [1, 4, 7, 3, 4, 6], [2, 5, 8, 7, 3, 2], [3, 6, 9, 6, 7, 8], [1, 1, 1, 2, 3, 6] ];ExampleLet’s ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
103 Views
We are required to write a JavaScript function that takes in a string and any number of characters specified as separators. Our function should return a splitted array of the string based on all the separators specified.For example −If the string is −const str = 'rttt.trt/trfd/trtr, tr';And the separators are −const sep = ['/', '.', ', '];Then the output should be −const output = [ 'rttt', 'trt', 'trfd', 'trtr' ];ExampleFollowing is the code −const str = 'rttt.trt/trfd/trtr, tr'; const splitMultiple = (str, ...separator) => { const res = []; let start = 0; for(let i = 0; ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
267 Views
Given an array of integers, we are required to write a function that takes this array and finds the one element that appears an odd number of times. There will always be only one integer that appears an odd number of times.We will approach this problem by sorting the array. Once sorted, we can iterate over the array to pick the element that appears for odd number of times.ExampleFollowing is the code −const arr = [20, 1, -1, 2, -2, 3, 3, 5, 5, 1, 2, 4, 20, 4, -1, -2, 5]; const findOdd = arr => { let ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
249 Views
Let’s say the following is our string. Some text is surrounded by special character hash(#) −var values = "My Name is #yourName# and I got #marks# in JavaScript subject";We need to replace the special character with valid values. For this, use replace() along with shift().ExampleFollowing is the code −var values = "My Name is #yourName# and I got #marks# in JavaScript subject"; const originalValue = ["David Miller", 97]; var result = values.replace(/#([^#]+)#/g, _ => originalValue.shift()); console.log(result);To run the above program, you need to use the following command −node fileName.js. Here, my file name is demo298.js.OutputThis will produce the following output ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
2K+ Views
The HTML input value is a string. To convert the string to integer, use parseInt().ExampleFollowing is the code − Live Demo Document GetANumber function result() { var numberValue = document.getElementById("txtInput").value; if (!isNaN(numberValue)) console.log("The value=" + parseInt(numberValue)); else console.log("Please enter the integer value.."); } To run the above program, save the file name “anyName.html(index.html)”. Right click on the file and select the option “Open with ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
158 Views
Let’s say the following is our object −var details = { "STUDENTNAME": "John", "STUDENTAGE": 21, "STUDENTCOUNTRYNAME": "US" }As you can see above, the keys are in capital case. We need to turn all these keys to lower case. Use toLowerCase() for this.ExampleFollowing is the code −var details = { "STUDENTNAME": "John", "STUDENTAGE": 21, "STUDENTCOUNTRYNAME": "US" } var tempKey, allKeysOfDetails = Object.keys(details); var numberOfKey = allKeysOfDetails.length; var allKeysToLowerCase = {} while (numberOfKey--) { tempKey = allKeysOfDetails[numberOfKey]; allKeysToLowerCase[tempKey.toLowerCase()] = details[tempKey]; } console.log(allKeysToLowerCase);To run the above program, you need to use the following command −node ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
3K+ Views
Let’s say the following is our table − StudentName StudentCountryName JohnDoe UK DavidMiller US To get id from tr tag and display it in a new td, use document.querySelectorAll(table tr).ExampleFollowing is the code − Live Demo Document td, th, table { border: 1px solid black; margin-left: 10px; ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
464 Views
Yes, you can pass default parameters in nested objects.Following is the code −ExampleFollowing is the code −function callBackFunctionDemo({ cl: { callFunctionName = "callBackFunction", values = 100 } = {} } = {}) { console.log(callFunctionName); console.log(values); } //This will print the default value. // 100 callBackFunctionDemo(); //This will print the given value. //500 callBackFunctionDemo({ cl: { values: 500 } });To run the above program, you need to use the following command −node fileName.js.Here, my file name is demo296.js.OutputThis will produce the following output on console −PS C:\Users\Amit\javascript-code> node demo296.js callBackFunction 100 callBackFunction 500
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
63 Views
Let’s say our original string is the following with repeated letters −var values = "DDAAVIDMMMILLERRRRR";We want to remove the repeated letters and precede letters with numbers. For this, use replace() along with regular expression.ExampleFollowing is the code −var values = "DDAAVIDMMMILLERRRRR"; var precedingNumbersInString = values.replace(/(.)\1+/g, obj => obj.length + obj[0]); console.log("The original string value=" + values); console.log("String value after preceding the numbers ="); console.log(precedingNumbersInString);To run the above program, you need to use the following command −node fileName.js. Here, my file name is demo295.js.OutputThis will produce the following output on console −PS C:\Users\Amit\javascript-code> node demo295.js The original string value=DDAAVIDMMMILLERRRRR String value ... Read More