I need to get the values of the parameters of a JSON model I have.
My output returns:
console.log(this.model);
{ year:2017, month:08, day:05}
I need to get the values and create a object for example date='2017-08-05'
.
I need to get the values of the parameters of a JSON model I have.
My output returns:
console.log(this.model);
{ year:2017, month:08, day:05}
I need to get the values and create a object for example date='2017-08-05'
.
Depending on what you need to do with it, you could use a JavaScript template literal: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals
myNewObject.date = `${this.model.year}-${this.model.month}-${this.model.day}`;
If the date values are really numbers and not strings, then you may need to "0" pad them. There is an example for this here: How to output integers with leading zeros in JavaScript