Categories
JavaScript

Array entries method in JavaScript

We have already covered several methods regarding arrays in JavaScript. Today we are going to speak about the array entries method in JavaScript. The entries() method returns a new Array Iterator object that contains the key/value pairs for each index in the array, as per MDN. What does this mean? It means that an entries() […]

Categories
JavaScript

How to bind events to dynamically created elements in JavaScript

When working with JavaScript and DOM, we often find ourselves in need of creating some elements dynamically. Especially when working with some tables and fetching data from the server. Sometimes we have to bind events to dynamically created elements. And that is exactly what we are going to do now. When jQuery was in use […]

Categories
JavaScript

How to warn users when the connection is lost?

There are times when we need to track users’ internet connection. This is especially useful if we are building CRM, CMS, or other content-related software. Maybe the user is trying to save something and the connection is lost, instead of losing what he/she already did, we can warn our user that connection is lost and […]

Categories
JavaScript

4 easy ways to add class to an element using JavaScript

When working with DOM we often find ourselves in need to manipulate elements’ class. Today we are going to work on how to add class to an element using JavaScript. We will explore 4 ways on how to add class to any element in the DOM, including body and html element. Add class using className […]

Categories
JavaScript

Arrow functions in JavaScript. How to easily implement them?

Arrow functions were introduced in ES6, as a way to make code more readable and concise. Regular functions can be overkill for some tasks. Arrow functions have a simple syntax, but they also have some limitations. As per MDN there are differences and limitations: Does not have its own bindings to this or super, and […]

Categories
JavaScript

JavaScript sort method – part 2

Welcome to JavaScript sort method part 2. We already wrote on how to sort strings and numbers. Today we are talking about how can we sort objects. Similar to arrays, we can sort objects by some key. In the previous example, we sorted object by obj.id. We can do the same, but with obj.name. How […]

Categories
JavaScript

JavaScript sort method – part 1

We have already talked about JavaScript Arrays filter method and JavaScript Arrays map method, and today we are talking about JavaScript sort method. .sort() method sorts data alphabetically and numerically either in ascending or descending order. By default .sort() is sorting data alphabetically in ascending order. This means that “Audi” comes before “BMW” (nothing new, […]

Categories
JavaScript

JavaScript find method

The JavaScript find method returns the value of the first element in the provided array that satisfies the provided testing function. If no values satisfy the testing function, undefined is returned, as per MDN. This basically means that we need to provide some criteria, in form of, callback, function. Then, an array is iterated and the callback […]

Categories
JavaScript

Validate files in JavaScript easily using these 2 methods

In our last article How to easily upload files using Fetch API? we discussed how we can upload files. In this article, we are going to learn how to validate files before we upload them. In order to be totally on board, we recommend reading the previous article. The first thing we are going to […]

Categories
JavaScript

How to easily upload files using Fetch API?

Every developer comes to a point in a career where he/she needs to upload files to the server. Before, we were using full page reload by providing method and action to our form element. After that AJAX came. We either used jQuery’s $.ajax() API, or Vanilla JS XMLHttpRequest. Today, we have another option and it […]