Use reduce
to iterate over the array and call each function, and pass along the return value to the next iteration as the accumulator:
// using just a single object to make the indentation much more readable:
const obj = {
foo(arg) {
console.log('foo called with ' + arg);
return this;
},
bar(arg2) {
console.log('bar called with ' + arg2);
return this;
},
foobar(argA, argB) {
console.log('foobar called with ' + argA + ' ' + argB);
return this;
},
execute(arg5) {
console.log('execute called with ' + arg5);
return this;
}
};
const arr = [
["foo", ["asdf"]],
["bar", ["other"]],
["foobar", [123, "hi"]],
["execute", ["today"]]
];
arr.reduce((a, [key, args]) => a[key](...args), obj);
I have a <CountDown/> component that I'd like to hold it's own logic so it can be reusable else where in the app. I'm struggling to reason how could I setState to show:true on a sibling ...
I have a <CountDown/> component that I'd like to hold it's own logic so it can be reusable else where in the app. I'm struggling to reason how could I setState to show:true on a sibling ...
I can save all data varchar/text element from my form, but I can't save my path image. Whats is wrong with my code? Lets see my create.blade.php I can save value of var deadline but I can't save ...
I can save all data varchar/text element from my form, but I can't save my path image. Whats is wrong with my code? Lets see my create.blade.php I can save value of var deadline but I can't save ...
const A = [1,2,3,4,5] const B = [6,7,8,9,10] const C = []; for (let j=0; j<A.length;j++){ C[j] = C[[A[j],B[j]] } I want to create a 2D array C such that C = [[1,6],[2,7],[3,8],[4,9],[...
const A = [1,2,3,4,5] const B = [6,7,8,9,10] const C = []; for (let j=0; j<A.length;j++){ C[j] = C[[A[j],B[j]] } I want to create a 2D array C such that C = [[1,6],[2,7],[3,8],[4,9],[...
I've got multiple items, some of them with the same title. I want to create an multidimensional array with the title as the first key and a unique number as the second key. So it's possible to ...
I've got multiple items, some of them with the same title. I want to create an multidimensional array with the title as the first key and a unique number as the second key. So it's possible to ...