🖖 Greetings, this site is prototype for low code CMS deployments: Discover MoreStar on GitHub

SKNOW.IT

Cover Image for Optimised Selection (with JavaScript)

Optimised Selection (with JavaScript)

When using JavaScript, selecting elements from the DOM (Document Object Model) is a common task.

As is selection of an item from within a list, often only after checking if that item meets certain condition(s).

There are several ways to achieve this, the performance of selecting elements can have a significant impact on your application’s speed and responsiveness.

Here are some optimized methods for selecting elements in JavaScript:

Selection

getElementById: This method is very fast as it directly accesses an element by its unique ID.

const element = document.getElementById("elementId");

querySelector: This method allows you to use CSS selector syntax to target elements. It returns the first matching element.

const element = document.querySelector(".className");

///* let obj = buttons.find(t => t.id === e); if (obj) { obj.checked = !obj.checked; console.log(obj); } */

setDisplay(e.map(button => (button[id] === e ? {checked: true} : button)));

Standard built-in objects – Keyed collections

Standard built-in Array object methods

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array

Standard built-in Object object methods

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object

Standard built-in Number object methods

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number

Standard built-in String object methods

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String

Standard built-in String object methods

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON

GET IN TOUCH

Shaun Knowles
Shaun Knowles
Wrote this on
Categrised as:
Uncategorised

More Articles

Cover Image for How to Check and Update Your Git Version

How to Check and Update Your Git Version

Change is inevitable and, in the technical world, usually beneficial. Keeping your Git installation up to date is highly recommended, it gives you all the latest features, improvements, bug fixes, and more. Let’s see how to check which Git version you’re currently using and how to update it to the latest version. To stay up […]

Read More… from How to Check and Update Your Git Version

Shaun Knowles
Shaun Knowles
Cover Image for Next Generation Eco Friendly WordPress Websites

Next Generation Eco Friendly WordPress Websites

Do you want a WordPress website that is truly unique and reflects your brand? We design and build high performance websites for all purposes. […]

Read More… from Next Generation Eco Friendly WordPress Websites

Shaun Knowles
Shaun Knowles