- 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 9313 Articles for Object Oriented Programming
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
567 Views
Let’s say the following is our dropdown − John David Chris Mike Bob Carol Following is our array −var listOfNames = ["Chris", "Robert", "Mike"];To check whether the selected list value contains a value in array, use −$(‘select’).on(‘change’).Example Live Demo Document John David Chris Mike Bob Carol var listOfNames = ["Chris", "Robert", "Mike"]; $('select').on('change', function() { var name = this.value.split(' ')[0]; if($.inArray(name, listOfNames) > -1) { console.log('This is present in list ... Read More
![Mandalika](https://www.tutorialspoint.com/assets/profiles/223769/profile/60_143952-1595686763.jpg)
332 Views
A DB2 collection is a physical quantity which is used to group the packages. A collection can be simply termed as a group of DB2 packages. By using collections we can bind the same DBRM into different packages. In order to delete all the DB2 packers under a collection, we can issue below command.FREE PACKAGE(COLL1.*)The FREE PACKAGE reserved word is followed by the name of collection i.e. COLL1. The * after the collection name indicates that we need to perform delete action for all the packages under the said collection.
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
162 Views
Let’s say the following is our list −var details=[ {id:101, name:"John", age:21}, {id:111, name:"David", age:24}, {id:1, name:"Mike", age:22}, {id:"", name:"Sam", age:20}, {id: 1, name:"Carol", age:23}, {id:null, name:"Robert", age:25}, {id:1, name:"Adam", age:24}, {id:"", name:"Chris", age:23} ];You can use the concept of filter to retrieve values based on specific ID.Examplevar details=[ {id:101, name:"John", age:21}, {id:111, name:"David", age:24}, {id:1, name:"Mike", age:22}, {id:"", name:"Sam", age:20}, {id: 1, name:"Carol", age:23}, {id:null, name:"Robert", age:25}, {id:1, name:"Adam", age:24}, {id:"", name:"Chris", age:23} ]; var getIdWithValue1 = details.filter(obj => obj.id === 1); console.log(getIdWithValue1);To ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
515 Views
Let’s say the following are our coordinates −var listOfStrings = ["10.45322, -6.8766363", "78.93664664, -9.74646646", "7888.7664664, -10.64664632"];To convert the above into two float lists of Latitude and Longitude, use split() on the basis of comma(, ) along with map().Examplevar listOfStrings = ["10.45322, -6.8766363", "78.93664664, -9.74646646", "7888.7664664, -10.64664632"]; var latitude = []; var longitude = []; listOfStrings.forEach(obj => obj.split(', ') .map(Number) .forEach((value, index) => [latitude, longitude][index].push(value)) ); console.log("All positive value is latitude=") console.log(latitude); console.log("All negative value is longitude=") console.log(longitude);To run the above program, you need to use the following command −node fileName.js.Here, my file name is demo180.js.OutputThis will produce the following output ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
294 Views
To ignore a specific value, use the logical Not (!) operator in if condition and fetch watching you want to include.Examplevar customerDetails=[ { customerName:"John", customerAge:28, customerCountryName:"US" }, { customerName:"David", customerAge:25, customerCountryName:"AUS" }, { customerName:"Mike", customerAge:32, customerCountryName:"UK" } ] for(var i=0;i node demo179.js The country name is=US The country name is=UK
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
426 Views
To select random values from an array, use the concept of Math.random().Examplevar subjectNames = ["Javascript", "MySQL", "Java", "MongoDB", "Python","Spring Framework"]; for(var index = subjectNames.length - 1; index > 0; index--){ var rndIndex = Math.floor(Math.random() * (index + 1)); var subjNameTemp = subjectNames[rndIndex]; subjectNames[rndIndex] = subjectNames[index]; subjectNames[index] = subjNameTemp; } var getRandomSubjectName = subjectNames.slice(0, 3); console.log(getRandomSubjectName);To run the above program, you need to use the following command −node fileName.js.Here, my file name is demo178.js.OutputThis will produce the following output −PS C:\Users\Amit\javascript-code> node demo178.js [ 'Javascript', 'MySQL', 'Python' ]
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
12K+ Views
Let’s say the following is our array of objects −var details = [{ studentName: "John", studentMarks: 92 }, { studentName: "David", studentMarks: 89 }, { studentName: "Mike", studentMarks: 98 }, ];To get only specific values in an array of objects in JavaScript, use the concept of filter().Examplevar details = [{ studentName: "John", studentMarks: 92 }, { studentName: "David", studentMarks: 89 }, { studentName: "Mike", studentMarks: 98 }, ]; var specificValuesFromArray = details.filter(obj => obj.studentMarks === 92 || obj.studentMarks === 98); console.log(specificValuesFromArray)To run the above program, you need to ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
340 Views
For this, you can use filter() along with map().Exampleconst details =[ { customerName: 'John', customerCountryName: 'UK', isMarried :true }, { customerName: 'David', customerCountryName: 'AUS', isMarried :false }, { customerName: 'Mike', customerCountryName: 'US', isMarried :false } ] let tempObject = details.filter(obj=> obj.isMarried == true); tempObject["customerNameWithIsMarriedFalse"] = details.filter(obj => obj.isMarried== false).map(obj => obj.customerName); console.log(tempObject);To run the above program, you need to use the following command −node fileName.js.Here, my file name is demo176.js.OutputThis will produce the following output −PS C:\Users\Amit\javascript-code> node demo176.js [ { customerName: 'John', customerCountryName: 'UK', isMarried: true }, customerNameWithIsMarriedFalse: [ 'David', 'Mike' ] ]
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
905 Views
For this, use click() along with parseInt().Example Live Demo Document 10 addValue10EachTimePressMe addValue = 0; $("#addSequenceOf10").click(function() { var actualValue = parseInt($("#add").html()); addValue =addValue+ actualValue; $("#sequenceValue").html(addValue); }); To run the above program, just save the file name anyName.html(index.html) and right click on the file and select the option open with live server in VS Code editor.OutputThis will produce the following output −Now, press the button you will get 10 then 20 30 40…….N; as in the below output −After clicking one more time, the snapshot is as follows.This will produce the following output −
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
535 Views
Let’s say the following is our string −var sentence = 'My Name is John, Smith I live in US'; console.log("The original value="+sentence);We need to remove the text after comma and the following word i.e. after removing “I live in US” and keeping the rest. This would be the resultant string −My Name is John, SmithFor this, use match() along with split().Examplevar sentence = 'My Name is John, Smith I live in US'; console.log("The original value="+sentence); var expression = sentence.match(/([^, ]*)(.*)/)[1]; var positionForComma = sentence.match(/([^, ]*), (.*)/)[2].split(' ')[1] var newValue = expression + ', ' + positionForComma console.log("Updated="+newValue);To run the above ... Read More