以下代码examines the content of inputData.body
for a 32-character string match,并且 - 尽我所知,将任何匹配放在数组中。如果没有正则表达式匹配,则返回“false”
// stores an array of any length (0 or more) with the matches
var matches = inputData.body.match(/\b[\w-]{32}\b/g)
// the .map function executes the nameless inner function once for each element of the array and returns a new array with the results
return matches.map(function (m) { return {str: m} })
我现在需要的代码中没有匹配的表达式的情况下,例如返回东西。字符串"false"
。
我是不是能够得到这个除了上班......
// stores an array of any length (0 or more) with the matches
var matches = inputData.body.match(/\b[\w-]{32}\b/g)
if (matches == null){
return 'false'
}
// the .map function executes the nameless inner function once for each element of the array and returns a new array with the results
return matches.map(function (m) { return {str: m} })
我应该如何去空虚的情况下,有条件地返回的东西吗?
被包裹在函数的代码? –
我认为你的代码应该可以工作。 – Barmar
你确定调用者已经准备好获得一个字符串作为该函数的结果吗?它可能期望一个数组。 – Barmar