L
L
Leo2014-05-01 10:18:06
In contact with
Leo, 2014-05-01 10:18:06

How to add a property to an object in VkScript (not through ".")?

There is this code:

var source = Args.source;
var targets = Args.targets;
// var common_friends = {};
var common_friends = [];
var req;
var parametr = "";
var start = 0;

// из строки с целями вынимаем каждую цель
while(start<=targets.length-1){
    if (targets.substr(start, 1) != "," && start != targets.length-1){
        parametr = parametr + targets.substr(start, 1);
    }
    else {
        // сразу делаем запросы, как только вытащили id
        req = API.friends.getMutual({"source_uid":source, "target_uid":parametr});
        common_friends = common_friends + req;
        // а нужно common_friends[parametr] = req; VkScript похоже не поддерживает
        parametr = "";
    }
    start = start + 1;
}

return common_friends;

The stored procedure in VKontakte takes as parameters: source (id) and targets(25 id separated by commas). Next, we extract targets by id and use them to get an array of mutual friends.
Now all this information needs to be sent back in a readable form:
{'id': [список общих друзей], 'id': [], 'id': [friend_id1, friend_id2],

But as I understand it, it is impossible to add a property to an object using square brackets - the usual
var a = {};
a["name"] = 123;

Returns error: non-variable in assignment
How else can you add a property to an object in VkScript?
var a = {};
a.name = 123;

In my case, not very suitable.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
L
Leo, 2014-05-01
@STLEON

var a = {"cname":456};
var b = {"name":123};
a = a + b;
return a;

Return
response: {
cname: 456,
name: 123
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question