es difícil de explicar, pero sigamos con un ejemplo
const exampleProperty = { log1: () => { console.log('log1') }, log2: () => { console.log('log2') }, log3: () => { console.log('log3') }, log4: () => { console.log('log4') } } for (let i = 0; i < 4; i++) { // now here I want to run all the functions in the example Property // I imagined it something like exampleProperty.log${i} // but this is invalid syntax }Puede haber una respuesta muy fácil a esto, pero como soy nuevo, realmente no puedo imaginar qué hacer.
Si quisiera enumerar todos los métodos
const exampleProperty = { log1: () => { console.log('log1') }, log2: () => { console.log('log2') }, log3: () => { console.log('log3') }, log4: () => { console.log('log4') } } Object.values(exampleProperty).forEach(p => p())Ejemplo de trabajo, usando backticks
const exampleProperty = { log1: () => { console.log('log1') }, log2: () => { console.log('log2') }, log3: () => { console.log('log3') }, log4: () => { console.log('log4') } } for (let i = 1; i <= 4; i++) { // now here I want to run all the functions in the example Property // I imagined it something like exampleProperty[`log${i}`](); // but this is invalid syntax }