<- Startseite / Anleitungen / Smarthome / ioBroker
ioBroker - Javascript Tipps
Funktionen und Methoden
Kalenderwoche ermitteln
Date.prototype.getWeekNumber = function(){
let d = new Date(+this);
d.setHours(0,0,0);
d.setDate(d.getDate()+4-(d.getDay()||7));
return Math.ceil((((d-new Date(d.getFullYear(),0,1))/8.64e7)+1)/7);
};
var date = new Date();
log(date.getWeekNumber());
1
2
3
4
5
6
7
8
9
10
2
3
4
5
6
7
8
9
10
Ausgabe: {die KW}
Grundlagen Promise
Promise Ressourcen
- Schnelleinstieg zum Thema JavaScript Promise
- 2015 Einführung in die asynchrone JavaScript-Programmierung
Grundlagen async/await
Typdekleration der js Datei
Objekte vergleichen
Quelle: Funktion und Artikel vonhttps://web-developer-blog.com/2014/04/objekte-vergleichen-in-javascript.html
function isEquivalent(a, b) {
// Create arrays of property names
var aProps = Object.getOwnPropertyNames(a);
var bProps = Object.getOwnPropertyNames(b);
// If number of properties is different,
// objects are not equivalent
if (aProps.length != bProps.length) {
return false;
}
for (var i = 0; i < aProps.length; i++) {
var propName = aProps[i];
// If values of same property are not equal,
// objects are not equivalent
if (a[propName] !== b[propName]) {
return false;
}
}
// If we made it this far, objects
// are considered equivalent
return true;
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25