For example the following code prints
{ key: 'b' }
function myFunc(key, value) {
myFunc2({key: value});
}
function myFunc2(obj) {
console.log(obj);
}
myFunc('a', 'b');
How would I get it to print
{ 'a': 'b' }
You can call a function inside an object by declaring the function as a property on the object and invoking it, e.g. obj. sum(2, 2) . An object's property can point to a function, just like it can point to a string, number or other values. Copied!
Functions in the functional programming paradigm can be passed to other functions as parameters. These functions are called callbacks. Callback functions can be passed as arguments by directly passing the function's name and not involving them.
You need to make the object first, then use [] to set it. var key = "happyCount"; var obj = {}; obj[key] = someValueArray; myArray. push(obj);
keys() is a built-in JavaScript function that returns an array of the given object's property names in the same order as we get with a standard loop. The Object. keys() method takes an object as an argument and returns the array of strings representing all the enumerable properties of a given object.
You can add properties separately from construction:
function myFunc(key, value) {
var item = {};
item[key] = value;
myFunc2(item);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With