I have the following function:
String.prototype.format = function() {
var args = arguments;
return this.replace(/{(\d+)}/g, function(match, number) {
return typeof args[number] != 'undefined' ? args[number] : match;
});
};
Now say I have the following code defined:
var dataItem = { membershipId: 1, userId: 3 };
var dataKeyNames = 'membershipId,userId';
var url = '/Admin/User?MembershipId={0}&UserId={1}';
What I'd like to do is call the format function passing in each value from the data item (for each data key name). For example if there was only one data key name then I would be able to say:
var formattedUrl = url.format(dataItem[dataKeyNames]);
But I need to be able to do a split on the dataKeyNames and pass each corresponding value from the data item in as arguments in the format function.
I'd appreciate it if someone could show me how this is done. Thanks
dataKeyNames.split(',')? Then loop over the array and call.format()with the key's value?.map()on the split string, mixed with getting the respective values from the object, would give them the array they need to.applyto the function call