Skip to content

Category: JavaScript

Sorting an array of Objects in JavaScript

If you have an array in JavaScript that doesn’t contain just simple numeric or string values, but objects with properties instead: var employees=[]; employees[0] = {name:”Petar”, age:32}; employees[1] = {name:”Nikola”, age:17}; employees[2] = {name:”Milutin”, age:58}; employees[3] = {name:”Slavisa”, age:62}; The employees array above is an array of objects with properties of different data types, string and numeric. The sort() method can be used to sort the array based on the values of one of these properties, such as sorting the array by name or age. The basic idea is to… Read more Sorting an array of Objects in JavaScript

Hosting #Meteor app with #Modulus

Currently I am trying/learning development with Meteor framework. My first impressions are great! Some things were never that easy as they are with Meteor, it’s super fast, made with simplicity as core philosophy… I will write about Meteor in a separate post, when I learn enough of it and try it with some real world projects. At this point of time I want to bookmark here platform that enables hosting of Meteor apps – Modulus.io. Modulus is a PaaS (Platform as a Service) for hosting Node.js based apps with full support for Meteor apps.… Read more Hosting #Meteor app with #Modulus

Proper date comparison in #JavaScript

If you want to check if some variable contains valid date in JavaScript, this is the way that works properly in all cases: isValidDate: function(d) { if ( Object.prototype.toString.call(d) === “[object Date]” ) { // it is a date, but still it could be ‘Invalid date’ which could make trouble if ( isNaN( d.getTime() ) ) { // date is not valid return false; } else { // date is valid return true; } } else { // not a date return false; } }