Friday, April 20, 2018

JavaScript set object key by variable

ES6

var key = "name";
var person = {[key]:"John"};
console.log(person); // should print  Object { name="John"}

Before ES6

var person = {};
var key = "name";

person[key] /* this is same as person.name */ = "John";

console.log(person); // should print  Object { name="John"}

No comments:

Get Indian financial year based on date

This function lets you get the start and end date of Indian financial year based on given date. This can also be modified for US financia...