- 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
Ayush Gupta has Published 541 Articles
![Ayush Gupta](https://www.tutorialspoint.com/assets/profiles/134135/profile/60_13095-1568350695.jpg)
Ayush Gupta
8K+ Views
JS has 2 notations for creating object properties, the dot notation and bracket notation.To create an object property from a variable, you need to use the bracket notation in the following way −Exampleconst obj = {a: 'foo'} const prop = 'bar' // Set the property bar using the variable name ... Read More
![Ayush Gupta](https://www.tutorialspoint.com/assets/profiles/134135/profile/60_13095-1568350695.jpg)
Ayush Gupta
424 Views
You can't break from the forEach method and it doesn't provide to escape the loop (other than throwing an exception).You can use other functions like _.find from lodash instead −_.find − it breaks out of the loop when the element is found. For example, Example_.find([1, 2, 3, 4], (element) => ... Read More
![Ayush Gupta](https://www.tutorialspoint.com/assets/profiles/134135/profile/60_13095-1568350695.jpg)
Ayush Gupta
7K+ Views
The most efficient method to group by a key on an array of objects in js is to use the reduce function.The reduce() method executes a reducer function (that you provide) on each element of the array, resulting in a single output value.Exampleconst people = [ { name: 'Lee', ... Read More
![Ayush Gupta](https://www.tutorialspoint.com/assets/profiles/134135/profile/60_13095-1568350695.jpg)
Ayush Gupta
24K+ Views
You can dispatch events on individual elements using the dispatchEvent method. Let's say you have an element test with an onChange event −Event handler −document.querySelector('#test').addEventListener('change', () => console.log("Changed!"))Triggering the event manually −const e = new Event("change"); const element = document.querySelector('#test') element.dispatchEvent(e);This will log the following −Changed!Read More
![Ayush Gupta](https://www.tutorialspoint.com/assets/profiles/134135/profile/60_13095-1568350695.jpg)
Ayush Gupta
2K+ Views
To clear a localStorage data on browser close, you can use the window.onunload event to check for tab close.Let's say you have a local storage object called MyStorage as a global for the sake of this example. Then you can write an event handler −Examplewindow.onunload = () => { ... Read More
![Ayush Gupta](https://www.tutorialspoint.com/assets/profiles/134135/profile/60_13095-1568350695.jpg)
Ayush Gupta
66 Views
MEAN is an acronym for MongoDB, Express, Angular, and Node.js.MEAN.js and MEAN.io are the same things essentially as they both are scaffolded applications or a basic set up to use the above 4 things. These libraries/tools have these set up for you already.These allow you to not spend time on ... Read More
![Ayush Gupta](https://www.tutorialspoint.com/assets/profiles/134135/profile/60_13095-1568350695.jpg)
Ayush Gupta
621 Views
We can use the Node.contains method to do this check. The Node.contains() method returns a Boolean value indicating whether a node is a descendant of a given node, i.e. the node itself, one of its direct children (childNodes), one of the children's direct children, and so on.ExampleFor example, you are ... Read More
![Ayush Gupta](https://www.tutorialspoint.com/assets/profiles/134135/profile/60_13095-1568350695.jpg)
Ayush Gupta
118 Views
To add one day to date in JS, the setDate function is the best way. You can create the following function on the Date prototype to add days to the date.ExampleDate.prototype.addDays = function(days) { let d = new Date(this.valueOf()); d.setDate(d.getDate() + days); return d; } let date ... Read More
![Ayush Gupta](https://www.tutorialspoint.com/assets/profiles/134135/profile/60_13095-1568350695.jpg)
Ayush Gupta
703 Views
We can set the value of a select box using Javascript using the following. Suppose we have the following select box − Select Apple Strawberry Cherry Guava To set the value of this select element, we need to access it using querySelector. Then set the ... Read More
![Ayush Gupta](https://www.tutorialspoint.com/assets/profiles/134135/profile/60_13095-1568350695.jpg)
Ayush Gupta
284 Views
Object-oriented programming languages allow data hiding using private fields. They use these to hide the internals of classes. In JS there is no such in build support to hide/encapsulate the inner workings.We have Anonymous functions that can give you encapsulation in JS. Let us look at an example −Exampleconst HIDDEN_CONST ... Read More