What is property in hasOwnProperty in JavaScript?

hasOwnProperty returns a boolean value indicating whether the object on which you are calling it has a property with the name of the argument. For example: var x = { y: 10 }; console.log(x.hasOwnProperty(“y”)); //true console.log(x.hasOwnProperty(“z”)); //false However, it does not look at the prototype chain of the object. It’s useful to use it when … Read more

Private properties in JavaScript ES6 classes

Update: See others answer, this is outdated. Short answer, no, there is no native support for private properties with ES6 classes. But you could mimic that behaviour by not attaching the new properties to the object, but keeping them inside a class constructor, and use getters and setters to reach the hidden properties. Note that … Read more

Get the last item in an array

if (loc_array[loc_array.length – 1] === ‘index.html’) { // do something } else { // something else } In the event that your server serves the same file for “index.html” and “inDEX.htML” you can also use: .toLowerCase(). Though, you might want to consider doing this server-side if possible: it will be cleaner and work for people … Read more