Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save trianglesis/8ed6075fa7105f5fabf2b23b822cbcfa to your computer and use it in GitHub Desktop.
Save trianglesis/8ed6075fa7105f5fabf2b23b822cbcfa to your computer and use it in GitHub Desktop.
VK API: Parse json Args to array.
var myList = Args.post_id_array_str;
// List should end with separator, for exampe ","
// car myList = 111,222,333,444,
var listSeparator = ",";
var listItemsType = "integer";
var result = [];
var charsLength = myList.length;
var currentPosition = 0;
var previousSeparatorPosition = -1;
var item;
while (currentPosition < charsLength) {
if (myList.substr(currentPosition, 1) == listSeparator) {
item = myList.substr(previousSeparatorPosition + 1, currentPosition - previousSeparatorPosition - 1);
if (listItemsType == "integer") {
item = parseInt(item);
}
result.push(item);
previousSeparatorPosition = currentPosition;
}
currentPosition = currentPosition + 1;
}
var posts = result;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment