Photo by Olga Vyshnevska on Unsplash

Using Date Methods

const currentDate = new Date();
const dateTime = currentDate.getDate() + "/" +
(currentDate.getMonth() + 1) + "/" +
currentDate.getFullYear() + " @ " +
currentDate.getHours() + ":" +
currentDate.getMinutes() + ":" +
currentDate.getSeconds();


Photo by Sam Moqadam on Unsplash

Date.prototype.setHours

const d = new Date();
d.setHours(0, 0, 0, 0);
console.log(d)


Photo by William Bayreuther on Unsplash

Using Array.prototype.map, Sets, and the Spread Operator

const array = [{…


Photo by Richard T on Unsplash

Array.prototype.filter

const arr = [{
place: "san francisco",
name: "jane"
},
{
place: "san francisco",
name: "jane"
},
{
place: "new york"…


Photo by Anne Nygård on Unsplash

document.body.contains

<div>
hello world
</div>
const div = document.querySelector('div')
const isVisible = document.body.contains(div)
console.log(isVisible)


Photo by Agê Barros on Unsplash

Date.prototype.getTime and Date.prototype.setTime

const date = new Date(2021, 1, 1)
const h = 2
date.setTime(date.getTime() + (h * 60 * 60 * 1000))
console.log(date)


Photo by Lubo Minar on Unsplash

String.prototype.replace

const trimmed = 'abc\r\ndef'.replace(/(\r\n|\n|\r)/gm, "");
console.log(trimmed)


Photo by Florian Berger on Unsplash

Object.keys and Array.prototype.find

const object = {
a: 1,
b: 2,
c: 3
}
const value = 2;
const key = Object.keys(object).find(key …


Photo by Alexander Schimmeck on Unsplash

clientHeight and clientWidth

<p id='text'>
hello world
</p>
const fontSize = 12;
const text = document.getElementById("text");
text.style.fontSize = fontSize;
const height = text.clientHeight
const width = text.clientWidth
console.log(height, width)…


Photo by Anton Maksimov juvnsky on Unsplash

Setting the value Property

<input id='mytext'>
document.getElementById("mytext").value = "My value";

Call the setAttribute Method

John Au-Yeung

Web developer. Subscribe to my email list now at https://thewebdev.info/subscribe/. Email me at hohanga@gmail.com

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store