-
-
Save trianglesis/8ed6075fa7105f5fabf2b23b822cbcfa to your computer and use it in GitHub Desktop.
VK API: Parse json Args to array.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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