Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby-on-rails-4/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何迭代js变量数组?_Javascript - Fatal编程技术网

Javascript 如何迭代js变量数组?

Javascript 如何迭代js变量数组?,javascript,Javascript,嗯,这对我来说有点困惑,我想迭代一个数组来获得一个值,我不知道如何解释它: ccs_cc_args = ccs_cc_logsvc = function ccs_cc_logsvc(){var t=this;t.pStart="ccs_cc_log_startTime",t.pInit="ccs_cc_initParams",t.pId=t.genGuid(),"undefined"==typeof window[t.pStart]&&(window[t.pStart]=(n

嗯,这对我来说有点困惑,我想迭代一个数组来获得一个值,我不知道如何解释它:

ccs_cc_args = 

ccs_cc_logsvc = function ccs_cc_logsvc(){var t=this;t.pStart="ccs_cc_log_startTime",t.pInit="ccs_cc_initParams",t.pId=t.genGuid(),"undefined"==typeof window[t.pStart]&&(window[t.pStart]=(new Date).getTime()),t.ping=function(){t.pingCount++,t.pingCount>1&&t.sendEvent("Ping"),t.pingCount<=t.maxPing&&window.setTimeout(t.ping,t.pingPeriod)};try{t.host=window.location.href.substr(0,300)}catch(e){}t.cnt=0,t.init(),t.sendEvent("TInit",null,!0),t.setPing(0,15e3)}
ccs_cc_contentloader = function ccs_cc_contentloader(t){var e=this,c="ccs_loading_scripts";"undefined"==typeof window[c]&&(window[c]=[]),e.isLoading=!1,e.addedObjects=[],e.waitLoadScripts=[],e.cssToLoad=0,e.scriptToLoad=0,e.objName=t,e.addedRefs=[],e.loadingCSS=[],e.isLoadFinishing=!1,e.objectToLoad=null,e.contextId=null,e.lastScript=null,e.lastTarget=null,e.navigated=!0,e.defaultUrl={},e.loadingScripts=window[c],e.ccsHost=ccs_cc_log.ccsHost,e.skey=ccs_cc_log.skey,window.setInterval(function(t){return function(){t.navTo()}}(this),50)}

ccs_cc_log = [object Object]
ccs_cc_initParams = ,ws.pagecontent.com

ccs_cc_log_startTime = 1471905959132

ccs_cc_debug_lastUrl = http://ws.pagecontent.com/7f08cde9/script/hp-auto-pp?cpn=CPN&mf=HP&pn=T1C06…ean=UPC_EAN_CODE&lang=ES&market=MX&host=&nld=1

ccs_cc_loadQueue = 

ccs_loading_scripts = 
ccs_cc_ld_hp-auto-pp = [object Object]
ccs_cc_loge_aa0e4d = function ccs_cc_loge_aa0e4d(id, clientParams, args){var et; var serverParams;switch (id) {
case '5901d207': et='ProductHookLoad'; serverParams={"ServerTime":"1","ResultCode":"100"}; break;
} ccs_cc_log.logEvent (et, 'SKey=abcd74589&LCID=2415&Market=MX&Locale=ES-MEX&ZoneId=hp-auto-pp&ZoneVer=1&SMfgName=HP&SMfgPn=TOM025HAC6547&MfgId=23', serverParams, clientParams); }
ccs\u cc\u参数=

ccs_cc_logsvc=函数ccs_cc_logsvc(){var t=this;t.pStart=“ccs_cc_log_startTime”,t.pInit=“ccs_cc_initParams”,t.pId=t.genGuid(),“undefined”==typeof window[t.pStart]&&(window[t.pStart]=(new Date.getTime()),t.ping=function(){t.pingCount++,t.pingCount>1&&t.sendEvent(“ping”),t.pingCount虽然这在一开始是对一个非常可怕的想法的攻击,但是您可以通过像以前那样循环所有键并只保留那些与所需的变量名模式匹配的键来做到这一点

因此,在循环和打印键的代码中,请执行以下操作:

if(/^ccs_cc_loge_[0-9]+$/.test(key)) {
  // call code that needs to use this variable;
};

此正则表达式将匹配以ccs_cc_loge_X开头的任何变量,其中XXXX是任意数量的数字。这比使用字符串函数(如
)更为具体,并且与浏览器兼容。startsWith

代码图像可能不会得到很多答案,最好作为问题中的文本/代码,或者因为在您的情况下,图像是result,我会把图像放在最后。糟糕的格式。Pro-tip:更好地格式化你的代码。如果你这样做,你和其他人会更容易调试。正确的方向,谢谢&是的,我知道这是一个糟糕的想法,但不是我的
if(/^ccs_cc_loge_[0-9]+$/.test(key)) {
  // call code that needs to use this variable;
};