All stacks / Intents / Select element Also written as select elements
syntax Copy
arr.filter(callback(element, index, array))example Copy
const products = [
{ name: "Shirt" , price: 25 },
{ name: "Jacket" , price: 120 },
{ name: "Cap" , price: 15 },
];
const affordable = products.filter(p => p.price < 50 );
console.log(affordable.map(p => p.name));output
["Shirt", "Cap"]Note Returns a new array with elements that pass the test. The callback must return a truthy/falsy value.
syntax Copy
document.querySelector(selector)
document.querySelectorAll(selector)
document.getElementById(id)example Copy
const header = document.querySelector("h1" );
const buttons = document.querySelectorAll(".btn" );
const main = document.getElementById("main-content" );
buttons.forEach(btn => {
console.log(btn.textContent);
});Note querySelector returns the first match or null. querySelectorAll returns a static NodeList (does not auto-update). Use Array.from() if you need full array methods.
Element, Class & ID Selectors HC · CSS Selectors syntax Copy
element { }
.class { }
example Copy
p {
line-height: 1.6 ;
}
.alert {
padding: 12 px 16 px;
border-radius: 6 px;
}
position: sticky;
top: 0 ;
}Note Prefer classes over IDs for styling since IDs have much higher specificity and cannot be reused. IDs are fine for JavaScript hooks and anchor targets.
Related tasks