Ayush Gupta has Published 486 Articles

How to check if element exists in the visible DOM?

Ayush Gupta

Ayush Gupta

Updated on 27-Nov-2019 10:42:43

785 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

Increment a date in javascript without using any libraries?

Ayush Gupta

Ayush Gupta

Updated on 27-Nov-2019 10:41:22

190 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

How to programmatically set the value of a select box element using JavaScript?

Ayush Gupta

Ayush Gupta

Updated on 27-Nov-2019 10:39:19

1K+ 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

JavaScript Encapsulation using Anonymous Functions

Ayush Gupta

Ayush Gupta

Updated on 27-Nov-2019 10:37:08

446 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

The Pros and Cons of Using Ajax

Ayush Gupta

Ayush Gupta

Updated on 27-Nov-2019 10:35:33

6K+ Views

Ajax is a set of web development techniques using many web technologies on the client-side to create asynchronous web applications. With Ajax, web applications can send and retrieve data from a server asynchronously without interfering with the display and behavior of the existing page.Any other technology Ajax also has its ... Read More

Safely setting object properties with dot notation strings in JavaScript

Ayush Gupta

Ayush Gupta

Updated on 27-Nov-2019 10:34:36

989 Views

You can use lodash's set method to set properties at any level safely. Setting first-level properties are pretty straightforward. Nested property access is tricky and you should use a tested library like lodash for it.You can set a deeply nested object in the following way −Examplelet _ = require("lodash"); let ... Read More

Safely Accessing Deeply Nested Values In JavaScript

Ayush Gupta

Ayush Gupta

Updated on 27-Nov-2019 10:27:51

440 Views

You can use lodash's get method to get properties at any level safely. Getting first-level properties is pretty straightforward. Nested property access is tricky and you should use a tested library like lodash for it.You can access a deeply nested object in the following way −Examplelet _ = require("lodash"); let ... Read More

Accessing nested JavaScript objects with string key

Ayush Gupta

Ayush Gupta

Updated on 27-Nov-2019 10:23:09

2K+ Views

You can use lodash's get method to get properties at any level safely. Getting first-level properties is pretty straightforward. Nested property access is tricky and you should use a tested library like lodash for it.You can access a deeply nested object in the following way −Examplelet _ = require("lodash"); let ... Read More

How to Send and Receive JSON Data to and from the Server

Ayush Gupta

Ayush Gupta

Updated on 27-Nov-2019 10:20:22

3K+ Views

JavaScript can send network requests to the server and load JSON. JS does this using something called AJAX. AJAX stands for Asynchronous JavaScript and XML. JS has an API, fetch, to GET(receive) and POST(send) information to the server.You can use fetch to GET JSON data in the following way −Exampleconst ... Read More

Query-string encoding of a Javascript Object

Ayush Gupta

Ayush Gupta

Updated on 27-Nov-2019 10:16:51

229 Views

The query string is made up of query parameters and used to send data to the server. This part of the URL is optional. It needs to be constructed by the developer. This can be done using a native method called encodeURIComponent.The encodeURIComponent() function encodes a Uniform Resource Identifier (URI) ... Read More

Advertisements