let name = [ 'Aditi', 'Ayushi', ' Sanaya', 'Aditi', 'Aditi' ];
let newName = [...new Set(name)];
console.log( newName); // Output: ["Aditi", "Ayushi", " Sanaya"]
Sum of all numbers in an array
let num = [5, 3, 7, 2, 8,];
num.reduce((a, b) => a+b, 0); // Output: 25
Generate a random number in a range
Math.floor(Math.random() * 7); // In a range between 0 and 6
Convert string to character
let course = "JavaScript"
let char = [...course];
console.log(char); // Output: ["J", "a", "v", "a", "S", "c", "r", "i", "p", "t"]
Destructuring variable
let [aditi, ...name] = [ 'Aditi', 'Ayushi', ' Sanaya', 'Sumit'];
aditi;
name;
// Output: ["Ayushi", " Sanaya", "Sumit"]
Merging arrays
let name = [ "Aditi", "Ayushi", " Sanaya", "Sumit" ]
let Course = ["JavaScript", "React", "NodeJs"];
let nameAndCourse = [...name, ...Course];
console.log(nameAndCourse);
// Output: ["Aditi", "Ayushi", " Sanaya", "Sumit", "JavaScript", "React", "NodeJs"]
Convert to string
let num = 7 + " ";
console.log(num);
console.log(typeof num)
Convert to number
let num = "8";
num = +num;
console.log(num);
console.log(typeof num)
Resizing array
let num = [ 1, 2, 3, 4, 5 ];
array.length = 3;
console.log(array); // Output: [1, 2, 3]
Log values with variable names
let newCourses = "JavaScript";
console.log({ newCourses });