
A practical collection of JavaScript snippets for arrays, objects, strings,
Subhro Kr
subhbits.com

const fruits = [
"Mango",
"Apple",
"Apple",
"Cherry",
"Grapes",
"Grapes",
"Cherry"
];
const uniqueFruits = [...new Set(fruits)];
console.log(uniqueFruits);[ 'Mango', 'Apple', 'Cherry', 'Grapes' ]
const original = {
name: "Alice",
settings: {
theme: "dark",
notifications: { email: true, sms: false }
}
};
const copy = structuredClone(original);
copy.settings.notifications.email = false;
console.log("Cloned Object with Structured Clone ", copy);
console.log("Original Object ", original);Cloned Object with Structured Clone {
name: 'Alice',
settings: { theme: 'System', notifications: { email: false, sms: false } }
}
Original Object {
name: 'Alice',
settings: { theme: 'System', notifications: { email: true, sms: false } }const numbers = [6, 2, 6, 9, 10, 3];
console.log(Math.max.apply(null, numbers));
console.log(Math.min.apply(null, numbers));10
2const fruits = ["Apple", "Banana", "Cherry"];
const vegetables = ["Carrot", "Broccoli", "Spinach"];
fruits.push.apply(fruits, vegetables);
console.log(fruits);[ 'Apple', 'Banana', 'Cherry', 'Carrot', 'Broccoli', 'Spinach' ]