Reactjs 基于多个值减少数组
我正在开发一个工具来突出文本中给定的单词。它正在工作,但不区分大小写,我想检查Reduce函数中单词的大写、大写和小写版本: 这是我的密码:Reactjs 基于多个值减少数组,reactjs,reduce,Reactjs,Reduce,我正在开发一个工具来突出文本中给定的单词。它正在工作,但不区分大小写,我想检查Reduce函数中单词的大写、大写和小写版本: 这是我的密码: textItem.split(searchText) .reduce((strArray, currentValue, currentIndex) => ( currentIndex === 0 ? ([...strArray, currentValue]) : ([...strArray, <mark key={cur
textItem.split(searchText)
.reduce((strArray, currentValue, currentIndex) => (
currentIndex === 0 ?
([...strArray, currentValue]) :
([...strArray,
<mark key={currentIndex}>{searchText}</mark>,
currentValue])
),
[]);
textItem.split(searchText)
.reduce((strArray、currentValue、currentIndex)=>(
currentIndex==0?
([…strArray,currentValue]):
([…strArray,
{searchText},
当前值])
),
[]);
不幸的是,在第一次之后添加另一个拆分和缩减对我来说不起作用,我认为原因是reduce函数中的组件
如何检查文本中单词的大写、大写和小写版本?如果是字符串,为什么不使用字符串#替换?像
let text = 'Lorem Ipsum lattim rand stack ipsum';
const searchText = 'ipsum';
text = text.replace(new RegExp(searchText, 'gi'), match => {
return <mark>{match}</mark>;
});
let text='Lorem Ipsum latticm rand stack Ipsum';
const searchText='ipsum';
text=text.replace(新的RegExp(searchText,'gi'),match=>{
返回{match};
});
选项
gi
是使研究不区分大小写,并适用于所有事件。如果是字符串,为什么不使用字符串#替换?像
let text = 'Lorem Ipsum lattim rand stack ipsum';
const searchText = 'ipsum';
text = text.replace(new RegExp(searchText, 'gi'), match => {
return <mark>{match}</mark>;
});
let text='Lorem Ipsum latticm rand stack Ipsum';
const searchText='ipsum';
text=text.replace(新的RegExp(searchText,'gi'),match=>{
返回{match};
});
选项gi
是使研究不区分大小写,并适用于所有事件