JavaScript method reference
ECMAScript 2026
Look up the call syntax, try it, and check a common mistake.
On this page
array.map(callback)
Call a function for every item in this array and collect the returned values in a new array.
How to try it Open a browser tab, then open Developer Tools → Console. Type the example or paste it into the Console after reviewing it, then run it. Reload before repeating declarations with the same names.
const catalog = [
{ name: "Pen", price: 1500 },
{ name: "Notebook", price: 2500 },
{ name: "Folder", price: 3000 }
];
console.log(catalog.map(item => item.price + 100));
What to expect The new prices are [1600, 2600, 3100].
Common mistake A callback body with braces needs an explicit return to produce a value.
array.filter(callback)
Return a new array containing items that pass a test.
How to try it Open a browser tab, then open Developer Tools → Console. Type the example or paste it into the Console after reviewing it, then run it. Reload before repeating declarations with the same names.
const catalog = [
{ name: "Pen", price: 1500 },
{ name: "Notebook", price: 2500 },
{ name: "Folder", price: 3000 }
];
const matches = catalog.filter(item => item.price >= 2500);
console.log(matches.length);
What to expect Two items cost at least 2500 MMK.
Common mistake filter() always returns an array, even if it finds zero or one item.
string.trim()
Get a new string without whitespace at the beginning or end. Spaces inside the text stay.
How to try it Open a browser tab, then open Developer Tools → Console. Type the example or paste it into the Console after reviewing it, then run it. Reload before repeating declarations with the same names.
const text = " Desk Lamp ";
console.log("[" + text.trim() + "]");
What to expect The string contains Desk Lamp with its original middle space.
Common mistake Use the returned value. trim() leaves the original string unchanged.
document.querySelector(selector)
Return the first element matching a CSS selector, or null if none matches.
How to try it Save this example as a new .html file, then open it in your browser. After a change, save and reload.
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>document.querySelector(selector)</title>
</head>
<body>
<ul><li class="product">Pen</li><li class="product">Notebook</li></ul>
<script>
const firstProduct = document.querySelector(".product");
if (firstProduct) firstProduct.textContent = "Featured pen";
</script>
</body>
</html>
What to expect The first list item becomes Featured pen. The second stays Notebook.
Common mistake Use a dot before a class name and # before an id.