In this Article we will go through how to check if all array elements are equal to a given value 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 isEqual = (arr, value) => arr.every(item => item === value);
In this Article we will go through how to check if a string is an octal 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 isOctal = str => /^(0o)?[0-7]+$/i.test(str);
In this Article we will go through how to check if all items in an array are equal 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 areEqual = arr => arr.length > 0 && arr.every(item => item === arr[0]);
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;
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));
In this Article we will go through how to check if an object is a promise 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 isPromise = obj => !!obj && (typeof obj === 'object' || typeof obj === 'function') && typeof obj.then === 'function';
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;
In this Article we will go through how to check if an object is 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 isEmpty = obj => Reflect.ownKeys(obj).length === 0 && obj.constructor === Object;
In this Article we will go through how to check if an object is an 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:
const isArray = obj => Array.isArray(obj);
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);