'Accessing two inputs for use in ${}
I have a function that takes 3 inputs:
let logger = (title, date, type) => {
switch(type) {
case 'start' || 'end':
console.log(`${title} loop ${type} time: ${date.type}`);
break;
}
};
var startTime = new Date();
var endTime = new Date();
logger('tester', {start: startTime, end: endTime}, 'start');
I would like to do this without using a new variable.
As you can see I am trying to get the property from the object I pass in, I am trying to do this with ${} but I am having trouble:
tester loop start: [object Object].start
Solution 1:[1]
You need to use bracket notation:
console.log(`${title} loop ${type} time: ${date[type]}`);
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Brian |
