Removing the largest number from an array
To remove the largest value from an array of numbers we first need to find that number and can then filter it out.
Read full articleTo merge arrays in JavaScript, we can either concatenate them or use the spread operator. If we nest them in an array, they stay separate inside of that wrapping array instead.
const a = ["up", "down"]
const b = ["left", "right"]
const c = ["B", "A"]
// this nests the arrays in another array instead of merging them
[a, b, c] // ⇒ [["up", "down"], ["left", "right"], ["B", "A"]]
// we can concatenate many arrays at once with `.concat()`
a.concat(b, c) // ⇒ ["up", "down", "left", "right", "B", "A"]
// the spread operator also joins the arrays into one large array
[...a, ...b, ...c] // ⇒ ["up", "down", "left", "right", "B", "A"]
const a = ["up", "down"]
const b = ["left", "right"]
const c = ["B", "A"]
// this nests the arrays in another array instead of merging them
[a, b, c] // ⇒ [["up", "down"], ["left", "right"], ["B", "A"]]
// we can concatenate many arrays at once with `.concat()`
a.concat(b, c) // ⇒ ["up", "down", "left", "right", "B", "A"]
// the spread operator also joins the arrays into one large array
[...a, ...b, ...c] // ⇒ ["up", "down", "left", "right", "B", "A"]
const a = ["up", "down"]
const b = ["left", "right"]
const c = ["B", "A"]
// this nests the arrays in another array instead of merging them
[a, b, c] // ⇒ [["up", "down"], ["left", "right"], ["B", "A"]]
// we can concatenate many arrays at once with `.concat()`
a.concat(b, c) // ⇒ ["up", "down", "left", "right", "B", "A"]
// the spread operator also joins the arrays into one large array
[...a, ...b, ...c] // ⇒ ["up", "down", "left", "right", "B", "A"]
const a = ["up", "down"]
const b = ["left", "right"]
const c = ["B", "A"]
// this nests the arrays in another array instead of merging them
[a, b, c] // ⇒ [["up", "down"], ["left", "right"], ["B", "A"]]
// we can concatenate many arrays at once with `.concat()`
a.concat(b, c) // ⇒ ["up", "down", "left", "right", "B", "A"]
// the spread operator also joins the arrays into one large array
[...a, ...b, ...c] // ⇒ ["up", "down", "left", "right", "B", "A"]
To remove the largest value from an array of numbers we first need to find that number and can then filter it out.
Read full articleThe ternary operator isn’t limited to assigning values based on a condition. It also lets us switch between two near identical function calls.
Read full articleRegular JavaScript has no concept of required parameters. We can use default parameter values to emulate this feature.
Read full articleTo asynchronously fetch data in a React component using hooks, we can define and then call an asynchronous function inside of useEffect.
Read full articleWe can combine filter and includes to find which elements exist in both of two given arrays.
Read full articleIf an array contains flat values, we can turn them into objects where they become a property’s value.
Read full article