WEIRD: Javascript string.split() and forloop split prepends mysterious comma ',' to resulting string -


so messing around js objects, trying stuff out. taking request, json, object. selec .api path. want traverse object , store it's name can pull more json orm expirement. doesn't matter really. here json:

var fakerestresponse = function() {   return {     "swaggerversion": "1.2",     "apiversion": "1.0.0",     "apis": [{       "path": "/users"     }, {       "path": "/skills"     }, {       "path": "/resumes"     }],     "info": {}   }; };   function createsubstr(strin, thechar) {     var substr = [];      (var = 0; < strin.length; i++) {         var str = ' ';         if (strin[i] === thechar) {             console.log("found first match" + strin + ' str[i] ' + strin[i] + ' thechar ' + thechar + ' str: ' + str);             i++;             while (strin[i] !== thechar && strin[i] !== ',' && < strin.length && strin[i] !== '"') {                 if (str === ' ') str = strin[i];                 else str += strin[i];                 console.log(str + " : " + strin[i]);                 i++;             }             substr.push(str);             str = ' ';          }     }     console.log('return substr ' + substr);     return substr; } 

that returned server. after trying .split, see below, built manual function , weird stuff:

http://codepen.io/willbittner/pen/aobvwg

that code pen above shows .split('/') function returning weird objects:

expected: ['users','skills','resumes']  .split: [',users',',skills',',resumes'] 

now, if move function:

substr.push(str); str = ' '; 

out next scope, **

http://codepen.io/willbittner/pen/gjroev

**

you both loop , .split() producing whack comma.

so know has (likely) values in loop changing before accessed because overlooking something, can't figure out causes this!!

* note- don't want fix it, plz don't respond different way of doing it. want know why happens. *

to me- if there character appended on end, more acceptable, bug in code prepends string, shifts it! no characters lost! shifted guess lol.


Popular posts from this blog

c# - ODP.NET Oracle.ManagedDataAccess causes ORA-12537 network session end of file -

matlab - Compression and Decompression of ECG Signal using HUFFMAN ALGORITHM -

utf 8 - split utf-8 string into bytes in python -