Some, every and indexOf methods on arraysIntroduced in ES5, the only difference between Array.prototype.some() and Array.prototype.every() is the following: some() is used to check if at least one of the elements of the array passes the test implemented by the provided function; every() is...Dec 14, 2021·3 min read
Common Array methods in JavascriptCheck For The presence of an Element With indexOf() Since arrays can be changed, or mutated, at any time, there's no guarantee about where a particular piece of data will be on a given array, or if that element even still exists. Luckily, JavaScript ...Dec 6, 2021·8 min read
Nested loops for multi-dimensional arraysIf you have a multi-dimensional array like arr = [ [1, 2], [3, 4], [5, 6] ], you can loop through both the array and any sub-arrays. Here is an example: const arr = [ [1, 2], [3, 4], [5, 6] ]; for (let i = 0; i < arr.length; i++) { for (let j = ...Dec 2, 2021·1 min read
Object.keys, values, entries in JavascriptFor plain objects, the following methods are available: Object.keys(obj) – returns an array of keys. Object.values(obj) – returns an array of values. Object.entries(obj) – returns an array of [key, value] pairs. Please note that we have to call Obj...Nov 11, 2021·2 min read
Optional chaining with ?. in JavascriptThe optional chaining ?. stops the evaluation if the value before ?. is undefined or null and returns undefined. Further in this article, for brevity, we’ll be saying that something “exists” if it’s not null and not undefined. In other words, value?....Nov 11, 2021·2 min read
Difference between || and ?? in JavascriptHistorically, the OR || operator was there first. It exists since the beginning of JavaScript, so developers were using it for such purposes for a long time. On the other hand, the nullish coalescing operator ?? was added to JavaScript only recently,...Nov 11, 2021·2 min read
Destructuring on nested objects in ES6Destructuring simply implies breaking down a complex structure into simpler parts. In JavaScript, this complex structure is usually an object or an array. With the destructuring syntax, you can extract smaller fragments from arrays and objects. Destr...Nov 10, 2021·3 min read