Skip to content

Programming Articles

  • HOME
  • Python
  • JavaScript
  • C/C++
  • Java
  • Terms & Conditions and Privacy Policy
  • About US
Main Menu

JavaScript

JavaScript

How to display a JavaScript object?

Use native JSON.stringify method. Works with nested objects and all major browsers support this method. Link to Mozilla API Reference and other examples. Use a custom JSON.stringify replacer if you encounter this Javascript error How to display a …

How to display a JavaScript object? Learn More
JavaScript

How to check if a value is an object in JavaScript?

To check if a value is an object in JavaScript, use the following steps and reference code. If typeof yourVariable === ‘object’, it’s an object or null. If you want null, arrays or …

How to check if a value is an object in JavaScript? Learn More
JavaScript / JQuery

How to preview an image before it is uploaded using JavaScript?

You can preview an image before it is uploaded without using AJAX the following way: How to preview an image before it is uploaded? There are a couple ways you …

How to preview an image before it is uploaded using JavaScript? Learn More
JavaScript / JQuery

How to check if a variable is an array in JavaScript?

There are several ways of checking if an variable is an array or not. The best solution is the one you have chosen. This is the fastest method on Chrome, …

How to check if a variable is an array in JavaScript? Learn More
JavaScript

How to copy array by value in JavaScript?

Use this: Basically, the slice() operation clones the array and returns a reference to a new array. Also note that: For references, strings and numbers (and not the actual object), slice() copies object references …

How to copy array by value in JavaScript? Learn More
JavaScript

How to add new elements at the beginning of an array in JavaScript?

Use unshift to add new elements at the beginning of an array. It’s like push, except it adds elements to the beginning of the array instead of the end. unshift/push – add an …

How to add new elements at the beginning of an array in JavaScript? Learn More
HTML / JavaScript

How to retrieve the position (X,Y) of an HTML element using JavaScript?

The correct approach is to use element.getBoundingClientRect(): Internet Explorer has supported this for as long as you are likely to care about and it was finally standardized in CSSOM Views. All other browsers …

How to retrieve the position (X,Y) of an HTML element using JavaScript? Learn More
JavaScript

How to convert a string to an integer in JavaScript?

The simplest way would be to use the native Number function: If that doesn’t work for you, then there are the parseInt, unary plus, parseFloat with floor, and Math.round methods. parseInt: unary plus if your string is …

How to convert a string to an integer in JavaScript? Learn More
JavaScript

How to reload a page using JavaScript?

JavaScript 1.2 and newer JavaScript 1.1 JavaScript 1.0 Answer #2: If you are refreshing after an onclick then you’ll need to return false directly after How to reload a page using JavaScript? …

How to reload a page using JavaScript? Learn More
JavaScript

How to execute a JavaScript function when I have its name as a string?

Query: I have the name of a function in JavaScript as a string. How do I convert that into a function pointer so I can call it later? Depending on …

How to execute a JavaScript function when I have its name as a string? Learn More
JavaScript

How to get a random value from a JavaScript array?

Query explained: Consider: How can I select a random value from this array using JavaScript? How to get a random value from a JavaScript array? It’s a simple one-liner: For …

How to get a random value from a JavaScript array? Learn More
JavaScript

How to extend an existing array with another array without creating a new array in JavaScript?

Query explained: There doesn’t seem to be a way to extend an existing JavaScript array with another array, i.e. to emulate Python’s extend method. I want to achieve the following: I know …

How to extend an existing array with another array without creating a new array in JavaScript? Learn More
CSS / JavaScript / Web Development

How to make a div sticky on scroll using CSS and JavaScript?

In this post, I’ll share different ways to make an element sticky on scroll. How to make a div sticky on scroll using CSS and JavaScript? You could use simply …

How to make a div sticky on scroll using CSS and JavaScript? Learn More
JavaScript / Programming

What is the difference between call and apply in JavaScript?

Query: What is the difference between using Function.prototype.apply() and Function.prototype.call() to invoke a function? func.apply(); vs func.call(); Are there performance differences between the two aforementioned methods? When is it best to use call over apply and vice versa? Difference between …

What is the difference between call and apply in JavaScript? Learn More
Formatted Codes / JavaScript

How to get the current URL with JavaScript?

Query: All I want is to get the website URL. Not the URL as taken from a link. On the page loading, I need to be able to grab the …

How to get the current URL with JavaScript? Learn More
Formatted Codes / JavaScript

How to round off to 2 decimal places in javascript?

Sample query: I’d like to round at most 2 decimal places, but only if necessary. Input: Output: How can I do this in JavaScript? How to round off to 2 decimal …

How to round off to 2 decimal places in javascript? Learn More
Formatted Codes / JavaScript

How to check for an empty, undefined, or null string in JavaScript?

Sample query: Is there a simple string.Empty available in JavaScript, or is it just a case of checking for “”? How to check empty string in JavaScript? If you just want to check …

How to check for an empty, undefined, or null string in JavaScript? Learn More

Posts navigation

1 2 … 6 Next

Featured Posts

From UNIX to Linux – History of Linux

21st November 202010th September 2022

Best themes for Ubuntu: Make Ubuntu Beautiful

20th October 202010th September 2022

Strings in Python

12th September 202010th September 2022

Is Python hard to learn? Top best learning resources

18th April 202010th September 2022

Recent posts

  • How to pad a string with zeroes to the left?
  • What is the difference between process and thread?
  • How to generate a random alpha-numeric string in Java?
  • How to auto-resize an image to fit a ‘div’ container?
  • How to get a Docker container’s IP address from the host?
  • How to display a JavaScript object?
Copyright © 2023 Programming Articles.
Powered by WordPress and HitMag.