- 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 9312 Articles for Object Oriented Programming
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
114 Views
To repeat string, you can use Array() along with join().ExampleFollowing is the code − Document String.prototype.counter = function (value) { return new Array(value + 1).join(this); } console.log("The repeat string".counter(5)); To run the above program, save the file name anyName.html(index.html). Right click on the file and select the option “Open with live server” in VS Code editor.OutputThis will produce the following output: on console −
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
43 Views
If you will use equal operator(=) in if condition the if block will always be executed.You need to use == operator or === .ExampleFollowing is the code −var details = [ { id: 10001, name: "John" }, { id: 10002, name: "Bob" }, { id: 10003, name: "Carol" }, { id: 10004, name: "David" } ] var searchId = 10003; for (var index = 0; index < details.length; index++) { if (details[index].id === searchId) { console.log(details[index].id + " found"); break; } }To run the above program, you need to use the below command −node fileName.js.Here, my file name is demo322.js.OutputThis will produce the following output −PS C:\Users\Amit\javascript-code> node demo322.js 10003 found
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
1K+ Views
To get the number of true/ false values in an array, the code is as follows −var obj = [ { isMarried: true }, { isMarried: false }, { isMarried: true }, { isMarried: true }, { isMarried: false } ] function numberOfTrueValues(obj) { var counter = 0; for (var index = 0; index < obj.length; index++) { if (obj[index].isMarried === true) { counter++; ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
357 Views
To fetch a specific record, use find() with some condition.ExampleFollowing is the code −var obj=[ { studentId:101, studentName:"John" }, { studentId:102, studentName:"Bob" }, { studentId:103, studentName:"David" } ] const result = obj.find( (o) => { return o.studentId === 102 } ); console.log(result);To run the above program, you need to use the below command −node fileName.js.Here, my file name is demo315.js.OutputThis will produce the following output −PS C:\Users\Amit\javascript-code> node demo315.js { studentId: 102, studentName: 'Bob' }
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
132 Views
To fix this, you can use map() in JavaScript.The syntax is as follows −var anyVariableName= new Array(yourSize).fill().map(Object);ExampleFollowing is the code −var arrayOfObject = new Array(5).fill().map(Object); console.log(arrayOfObject);To run the above program, you need to use the following command −node fileName.js.Here, my file name is demo311.js.OutputThis will produce the following output −PS C:\Users\Amit\javascript-code> node demo311.js [ {}, {}, {}, {}, {} ]
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
1K+ Views
Use some conditions to stop after some time.The below code will stop in half a minute.ExampleFollowing is the code − Document var now = new Date().getTime(); var interval = setInterval(function () { if (new Date().getTime() - now > 30000) { clearInterval(interval); return; } console.log("working"); }, 2000); To run the above program, save the file name anyName.html(index.html) and right click on the file. Select the option “Open with live server” in VS Code editor.OutputThis will produce the following output −
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
311 Views
To sort an array of integers, use sort() in JavaScript.ExampleFollowing is the code −var arrayOfIntegers = [67, 45, 98, 52]; arrayOfIntegers.sort(function (first, second) { return first - second; }); console.log(arrayOfIntegers);To run the above program, you need to use the following command −node fileName.js.Here, my file name is demo310.js.OutputThis will produce the following output −PS C:\Users\Amit\javascript-code> node demo310.js [ 45, 52, 67, 98 ]
![Debomita Bhattacharjee](https://www.tutorialspoint.com/assets/profiles/210947/profile/60_171666-1594382095.jpg)
519 Views
We can click a link with the webdriver click and Javascript click. For the Selenium webdriver click of a link we can use link text and partial link text locator. We can use the methods driver.findElement(By.linkText()) and driver.findElement(By.partialLinkText()) to click.The links in an html code are enclosed in an anchor tag. The link text enclosed within the anchor tag is passed as argument to the driver.findElement(By.linkText()) method. The partial matching link text enclosed within the anchor tag is passed as argument to the driver.findElement(By.partialLinkText()) method. Finally to click on the link the click method is used.Let us see the html ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
1K+ Views
Extract the value and convert it from String to integer to get price value from span tag.ExampleFollowing is the code − Document Value= 10 $(document).ready(function () { var v = parseInt($(".purchase.amount") .text() .trim() .replace(', ', '')); var totalValue = v * 10; console.log(totalValue); ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
60 Views
To remove listener from outer function, use removeEventListener().ExampleFollowing is the code − Document Press Me var demoId = document.getElementById('demo'); demoId.addEventListener('click', function fun() { outerFunction(this, fun); }, false); function outerFunction(self, funct) { console.log('outer function is called....'); self.removeEventListener('click', funct, false); console.log("Listener has been removed...") } To run the above program, save the file name anyName.html(index.html) and right click on the file. Select the option “Open with live server” in VS Code editor.OutputThis will ... Read More