What Does ... (Three Dots) Mean In JavaScript

In this tutorial, you’ll learn what … ( three dots ) mean in JavaScript. Three Dots (…) which are know as Spread or Rest operator in JavaScript were introduced as an ES6 feature. Let’s first try to understand how three dots work as Spread operator in JavaScript. Spread Operator In JavaScript As the word Spread suggests the three dots (…) can be used to spread the contents on an array. [Read More]

JavaScript Program To Find Factorial Of A Number

In this tutorial, you’ll learn how to write a program to find factorial of a number. This post is a part of the JavaScript coding practice series. Factorial Of A Number First, let’s try to understand what the factorial means before trying to implement it. The factorial of a number n means, the product of all positive integers less than or equal to n. For example, the factorial of 4 is 4*3*2*1 = 24. [Read More]

JavaScript, Array Contains

How to check if Array Contains or Includes a value or string using JavaScript? You’ll be making use of Array.prototype.indexOf and Array.prototype.includes method to check if an array contains a value. Using IndexOf Method indexOf method gives you the element index inside an Array. So, if the element exists inside the array the index returned will be greater than -1. Here is how you use indexOf to check if a value is found in an array. [Read More]

How To Check If Object Has Key In JavaScript

In this tutorial, you’ll learn how to check if an object has key in JavaScript. You’ll be making use of in operator for checking if a key is present or not.

let obj = {
    'name' : 'Roy'
}

if('name' in obj){
    console.log('Found')
} else {
    console.log('Not found')
}

How To Check If Object Is Array In JavaScript

In this tutorial, you’ll learn how to check if an Object is an array in JavaScript. For checking if an array, JavaScript provides a built in method called isArray.

let arr = [];
    
if(Array.isArray(arr)){
    console.log('It is an array!!')
} else {
    console.log('Not an array!!')
}

How To Handle Promise Inside Loop

In this tutorial, you’ll learn how to handle JavaScript promise inside loop. Promises are an important concept in JavaScript programming. Getting a basic understanding about how Promises work in JavaScript is a must for every JavaScript developer. Assuming you have an understanding about how promises work, you will be able to understand this tutorial. Promise Inside For/ForEach Loop Create a folder called promise_loop. Initialize the project folder using npm. mkdir promise_loopcd promise_loopnpm initCreate a file called helper. [Read More]

How To Handle Promise Inside Promise

In this tutorial, you’ll learn how to handle JavaScript promise inside promise. Sometimes it’s required that the result from a promise is the input to another promise and so on. So, let’s see how a promise inside promise or promise chaining can be implemented. Using Promise Inside Promise Let’s start by creating a project directory called promise_inside. Navigate to the project directory and initialize the project using npm. mkdir promise_insidecd promise_insidenpm initOnce the project has been initialized, install the node module request. [Read More]

JavaScript : Find Duplicate Values In An Array

In this quick tutorial, you’ll learn how to find duplicates in an array using JavaScript. For finding duplicate values in JavaScript array, you’ll make use of the traditional for loops and Array reduce method. Using For Loop Let’s see how you can find duplicates in an array using for loop. The logic is you’ll separate the array into two array, duplicate array and unique array. You’ll iterate over the values in the array and push the items into unique list if it already doesn’t exist. [Read More]

How To Access Previous Promise Result In Then Chain

In this tutorial, you’ll learn how to access promise result in .then promise chain. In nested JavaScript Promise, sometimes it’s required to access one promise result in the promise chain. In such cases, you tend to assign promise result to a variable and then access it in promise chain. Let’s have a look at how you can access promise results in the entire chain. function getPromise(i){return new Promise(function(resolve, reject){setTimeout(function(){resolve({"data" : i});}, 2000);})}function queryPromiseChain(){let promiseOneResult;let promiseTwoResult;getPromise(1). [Read More]

How to Make API Calls Inside For-loop In JavaScript/

Making API call inside for loop is a common scenario that we face while creating web applications. In this tutorial, you’ll learn how to make API calls inside for loop in JavaScript. You’ll focus on how to make the API calls asynchronous inside for loop in JavaScript using Promise. Getting Started Let’s assume that you have an array of JSON objects with Ids. [{"Id": 10},{"Id": 20},{"Id": 30},{"Id": 40},{"Id": 50}]You need to iterate through the JSON objects array and for each Id you need to make an API call. [Read More]