不断获取错误对象REGEXP不是功能

时间:2019-10-31 05:43:43

标签: javascript discord.js

我正在使用API​​从Wiki获取船只外观,但我一直在获取 [object RegExp] is not a function错误。

我尝试使用Object.values()

title: `Class`,
            description: `${ship.class}`,
            thumbnail: {
                url: `${ship.skins.filter(/Default/)}`,
            },

(node:5532) UnhandledPromiseRejectionWarning: TypeError: [object RegExp] is not a function at Array.forEach (<anonymous>) at Object.run (C:\Users\Ash\Desktop\Discord.js Bot\commands\azurlane\azurship.js:20:36) at process._tickCallback (internal/process/next_tick.js:68:7) (node:5532) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1) (node:5532) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

1 个答案:

答案 0 :(得分:1)

ship.skins.filter(/Default/) //error here [object RegExp] is not a function

您将收到错误消息,因为filter是一个以回调函数为参数的函数。该回调函数接受3个参数:item,index,array

示例:

var result = [1,2,3].filter((item,index,array)=> item > 1 );

此处,当item大于1时,回调函数返回true,并且我们有一个过滤后的数组,其值为result,值为[2,3]