gpt4 book ai didi

javascript - 使用 lodash 链接进行字符串操作

转载 作者:行者123 更新时间:2023-11-29 10:40:11 24 4
gpt4 key购买 nike

我想更改字符串 “显示 XXX 期刊中的 8,868 篇研究论文;发表于 2000-01-01 和 2015-06-31 之间”

到: XXX期刊的新研究论文;从 2001-01-01 开始发布

我想出了以下使用 lodash 的代码:

 var desc = _.chain($('.description').text())
.thru(function (text) { return text.replace(/\s+/g, ' ') })
.thru(function (text) { return text.replace(/Showing\s[\d+\,*]+/, 'New') })
.split(';')
.map(function (phrase) {return phrase.replace('between', 'from').replace(/and\s[\d+-.]+/, 'onward') })
.join(';')
.value()

但我总是在 .thru(function (text) { return text.replace(/\s+/g, ' ') 行得到 Uncaught TypeError: undefined is not a function })

我做错了什么?

最佳答案

可能您使用的是过时版本的 lodash,因为您的代码适用于 lodash 3.9.3。请注意,_.thru 未在 lodash 2 中实现。*

关于javascript - 使用 lodash 链接进行字符串操作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30701375/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com