Sep 9, 2021 JavaScript
How to check if an array is not empty in JavaScript

In this Article we will go through how to check if an array is not empty only using single line of code in JavaScript. This is a one-line JavaScript code snippet that uses one of the most popular ES6 features => Arrow Function.

Let's define this short function:

const isNotEmpty = arr => Array.isArray(arr) && Object.keys(arr).length > 0;

Sep 9, 2021 JavaScript
How to check if an array is subset of other array in JavaScript

In this Article we will go through how to check if an array is subset of other array only using single line of code in JavaScript. This is a one-line JavaScript code snippet that uses one of the most popular ES6 features => Arrow Function.

Let's define this short function:

// Check if `b` is subset of `a`
const isSubset = (a, b) => (new Set(b)).size === (new Set(b.concat(a))).size;

Sep 9, 2021 JavaScript
How to check if a value is a plain object in JavaScript

In this Article we will go through how to check if a value is a plain object only using single line of code in JavaScript. This is a one-line JavaScript code snippet that uses one of the most popular ES6 features => Arrow Function.

Let's define this short function:

const isPlainObject = v => (!!v && typeof v === 'object' && (v.__proto__ === null || v.__proto__ === Object.prototype));

Sep 9, 2021 JavaScript
How to check if a value is a regular expression in JavaScript

In this Article we will go through how to check if a value is a regular expression only using single line of code in JavaScript. This is a one-line JavaScript code snippet that uses one of the most popular ES6 features => Arrow Function.

Let's define this short function:

const isRegExp = value => Object.prototype.toString.call(value) === '[object RegExp]';

Sep 9, 2021 JavaScript
How to check if a value is a string in JavaScript

In this Article we will go through how to check if a value is a string only using single line of code in JavaScript. This is a one-line JavaScript code snippet that uses one of the most popular ES6 features => Arrow Function.

Let's define this short function:

const isString = value => Object.prototype.toString.call(value) === '[object String]';

Sep 9, 2021 JavaScript
How to check if a value is an object in JavaScript

In this Article we will go through how to check if a value is an object only using single line of code in JavaScript. This is a one-line JavaScript code snippet that uses one of the most popular ES6 features => Arrow Function.

Let's define this short function:

const isObject = v => (v !== null && typeof v === 'object');

Sep 9, 2021 JavaScript
How to check if a value is base32 encoded in JavaScript

In this Article we will go through how to check if a value is base32 encoded only using single line of code in JavaScript. This is a one-line JavaScript code snippet that uses one of the most popular ES6 features => Arrow Function.

Let's define this short function:

const isBase32 = value => value.length % 8 === 0 && /^[A-Z2-7]+=*$/.test(value);

Sep 9, 2021 JavaScript
How to check if a value is base58 encoded in JavaScript

In this Article we will go through how to check if a value is base58 encoded only using single line of code in JavaScript. This is a one-line JavaScript code snippet that uses one of the most popular ES6 features => Arrow Function.

Let's define this short function:

// It doesn't accept the I, O, l characters 
const isBase58 = value => /^[A-HJ-NP-Za-km-z1-9]*$/.test(value);

Sep 9, 2021 JavaScript
How to check if a string is a hexadecimal number in JavaScript

In this Article we will go through how to check if a string is a hexadecimal number only using single line of code in JavaScript. This is a one-line JavaScript code snippet that uses one of the most popular ES6 features => Arrow Function.

Let's define this short function:

const isHexadecimal = str => /^[A-F0-9]+$/i.test(str);

Sep 9, 2021 JavaScript
How to check if a string is a mongodb objectid in JavaScript

In this Article we will go through how to check if a string is a mongodb objectid only using single line of code in JavaScript. This is a one-line JavaScript code snippet that uses one of the most popular ES6 features => Arrow Function.

Let's define this short function:

const isMongoId = str => str.length === 24 && /^[A-F0-9]+$/i.test(str);