原始对象↓
let obj1 = [{name:'蔬菜-1',id:'123'},
{name:'蔬菜-2',id:'122'},
{name:'新鲜蔬菜',id:'112'},
{name:'劣质苹果',id:'114'},
{name:'苹果-新增',id:'115'},
{name:'苹果-优质',id:'116'},
{name:'香蕉',id:'106'},
{name:'梨子',id:'156'}]
期待的效果↓
let result = [{name:'蔬菜',id:'123'},
{name:'苹果',id:'114'},
{name:'香蕉',id:'106'},
{name:'梨子',id:'156'}]
也就是如果name里面有相同的字符,改造后的name就是那个相同的字符,其余的去掉,然后id的话就用在前的第一个就行,没有相同的话就一起遍历到result里面,这该怎么写呢
不知道我的问题描述是否清晰,还请各位大神指教,小弟感激不尽!!
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…