我正在尝试将消息记录到浏览器(在我的例子中是 Safari)控制台,并通过组合几个字符串来构建它。但是,如果我包含一个可以单独记录的特定字符串,我会得到一个看起来像名为“No message”的数组,其内容是我要记录的字符串。
这段代码:
var msg1 = ["Outlier!",mName,"for",item[i_v].target,"start",item[i_v].start,"end",item[i_v].end].join(' ');
var msg2 = ["Outlier!",mName,"for",item[i_v].target].join(' ');
console.log(item[i_v].start);
console.log(item[i_v].end);
console.log(msg1);
console.log(msg2);
在控制台中生成:
[Log] 2016-01-27T00:00:00 (index.html, line 674)
[Log] 2016-01-04T18:25:51 (index.html, line 675)
[Log] No message (1) (index.html, line 676)
Outlier! percent_availability for BK.CMB.00.BHZ.M start 2016-01-27T00:00:00 end 2016-01-04T18:25:51
[Log] Outlier! percent_availability for BK.CMB.00.BHZ.M (index.html, line 677)
我不得不猜测 item[i_v].start
中的字符串有些古怪(根据 typeof
,它是一个字符串),但没有想一想它可能是什么,或者我可以做些什么来使用它来构建更大的字符串。任何有关如何这样做的想法,甚至是调查内容的建议,我们都将不胜感激。
最佳答案
关于string-concatenation - 使用 console.log() 写入字符串时为 "No message",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41026599/