Loop through an array in JavaScript

Three main options: for (var i = 0; i < xs.length; i++) { console.log(xs[i]); } xs.forEach((x, i) => console.log(x)); for (const x of xs) { console.log(x); } Detailed examples are below. 1. Sequential for loop:  Run code snippet Pros Works on every environment You can use break and continue flow control statements Cons Too verbose Imperative Easy to have off-by-one errors (sometimes also … Read more

Invariant Violation: Objects are not valid as a React child

In my component’s render function I have: everything renders fine, however when clicking the <li> element I receive the following error: Uncaught Error: Invariant Violation: Objects are not valid as a React child (found: object with keys {dispatchConfig, dispatchMarker, nativeEvent, target, currentTarget, type, eventPhase, bubbles, cancelable, timeStamp, defaultPrevented, isTrusted, view, detail, screenX, screenY, clientX, clientY, … Read more

window.location.href and window.open () methods in JavaScript

window.location.href is not a method, it’s a property that will tell you the current URL location of the browser. Changing the value of the property will redirect the page. window.open() is a method that you can pass a URL to that you want to open in a new window. For example: window.location.href example: window.open() example: … Read more

Invariant Violation: Objects are not valid as a React child

In my component’s render function I have: everything renders fine, however when clicking the <li> element I receive the following error: Uncaught Error: Invariant Violation: Objects are not valid as a React child (found: object with keys {dispatchConfig, dispatchMarker, nativeEvent, target, currentTarget, type, eventPhase, bubbles, cancelable, timeStamp, defaultPrevented, isTrusted, view, detail, screenX, screenY, clientX, clientY, … Read more

What is VanillaJS?

This is VanillaJS (unmodified): As you can see, it’s not really a framework or a library. It’s just a running gag for framework-loving bosses or people who think you NEED to use a JS framework. It means you just use whatever your (for you own sake: non-legacy) browser gives you (using Vanilla JS when working … Read more