Defines a table row
| Defines a header cell
| Defines a data cell
๐น Attributes:
border โ adds border
rowspan โ merges cells vertically
colspan โ merges cells horizontally
cellpadding โ space inside cell
cellspacing โ space between cells
๐น Example:
Array Methods in JavaScript
Arrays help store multiple values in one variable.
Array methods make it easy to process or transform data.
๐ธ reduce()
Used to reduce an array to a single value (like sum or total).
Syntax:
array.reduce(function(accumulator, currentValue) {
// logic
}, initialValue);
Example:
const numbers = [10, 20, 30];
const total = numbers.reduce((acc, curr) => acc + curr, 0);
console.log(total); // 60
๐ธ map()
Used to create a new array by applying a function to each element.
Does not modify the original array.
Syntax:
array.map((currentValue, index, array) => {
// return new value
});
Example:
const nums = [1, 2, 3];
const doubled = nums.map(n => n * 2);
console.log(doubled); // [2, 4, 6]
๐ธ filter()
Used to filter out elements that meet a specific condition.
Returns a new array with matching elements.
Syntax:
array.filter(currentValue => condition);
Example:
const numbers = [1, 2, 3, 4, 5];
const even = numbers.filter(num => num % 2 === 0);
console.log(even); // [2, 4]
๐ธ forEach()
Used to run a function for each element in an array.
It does not return anything.
Syntax:
array.forEach((currentValue, index, array) => {
// perform action
});
Example:
const fruits = ["apple", "banana", "mango"];
fruits.forEach(fruit => console.log(fruit));
Fetch API
๐น Definition:
The fetch() function is used to get data from a server (API) or send data to it.
It returns a Promise and works asynchronously, meaning it doesnโt block other code while waiting for a response.
๐น Syntax:
fetch(url, options)
.then(response => {
// handle response
})
.catch(error => {
// handle error
});
|