Forked from antixrist/gist:faf300eb04c1aeca9137
Last active
September 15, 2015 20:30
-
-
Save ishukshin/af235850ecc8cfce61a6 to your computer and use it in GitHub Desktop.
VK API: Parse json Args to array.
This file contains hidden or 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
/** | |
* For check: https://vk.com/dev/execute | |
*/ | |
// var myList = Args.list; | |
// var listSeparator = Args.listSeparator; | |
// var listItemsType = Args.listItemsType; | |
var myList = "123456,789012,345678,901234,567890"; | |
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; | |
} | |
return result; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment