Skip to content

Instantly share code, notes, and snippets.

@myogeshchavan97
myogeshchavan97 / get_all_scripts.js
Created November 13, 2019 08:50
Get all scripts included in a page
(function() { console.log(Array.from(document.scripts).forEach(script => console.log(script))) })()
@myogeshchavan97
myogeshchavan97 / time.js
Created November 13, 2019 11:59
Calculate the execution time
console.time('users');
axios.get('https://randomuser.me/api/?page=1&results=20')
.then(response => {
console.timeEnd('users');
});
@myogeshchavan97
myogeshchavan97 / group.js
Created November 13, 2019 12:09
Console grouping
axios.get('https://randomuser.me/api/?page=1&results=5')
.then(response => {
const users = response.data;
users.results.forEach(user => {
const name = user.name;
const location = user.location;
const email = user.email;
console.groupCollapsed('User Details');
console.log(name);
@myogeshchavan97
myogeshchavan97 / sum.js
Last active November 19, 2019 05:58
Get sum of numbers
function addNumbers(numbers) {
let sum = 0;
numbers.forEach(function(value) {
sum += value;
});
return sum;
}
@myogeshchavan97
myogeshchavan97 / sum_rest.js
Last active November 19, 2019 07:05
Get sum of numbers using rest operator
function addNumbers(...numbers) {
let sum = 0;
numbers.forEach(function(value) {
sum += value;
});
return sum;
}
@myogeshchavan97
myogeshchavan97 / max.js
Created November 19, 2019 06:31
Maximum of number using spread operator
const numbers = [1000, -20, 0, 40, 800];
const max = Math.max(...numbers);
console.log(max);
@myogeshchavan97
myogeshchavan97 / spread_concat.js
Last active November 19, 2019 06:45
Concat Two Arrays
const first = ["monday","tuesday"];
const second = ["wednesday", "thursday", "friday"];
const combined = [...first, ...second];
console.log(combined);
@myogeshchavan97
myogeshchavan97 / array_concat.js
Created November 19, 2019 06:47
Concat Two Arrays
const first = ["monday","tuesday"];
const second = ["wednesday", "thursday", "friday"];
const combined = first.concat(second);
console.log(combined);
@myogeshchavan97
myogeshchavan97 / concat.js
Created November 19, 2019 06:52
Concat Two Arrays
const first = ["monday","tuesday"];
const second = ["wednesday", "thursday", "friday"];
const combined = ["sunday", ...first, ...second, "saturday"];
console.log(combined);
@myogeshchavan97
myogeshchavan97 / array_spread.js
Created November 19, 2019 09:59
Array Spread Operator
const numbers = [10, 20, 30, 40, 50];
const [first, ...rest] = numbers;
console.log(first);
console.log(rest);