例如:
let arr = [{
key: 'https://www.baidu.com/',
}, {
key: 'https://www.taobao.com/',
}, {
key: 'https://www.xinlang.com/',
}, {
key: 'ali.com/',
}, {
key: 'xiaomi.com/',
}];
需求加上没有http://www.的值
let arr1 = []
arr.map((item, index) => {
if (!item.key.startsWith('https://www.')) {
arr1.push({key:'https://www.' + item.key})
} else {
arr1.push({key:item.key})
}
})
console.log("arr重组后",arr1)