
想把数组中所有name的参数名改成text,包括所有子集里面的name也改成text,代码其实很简单,如下:
var arr = [{
name:'小李家',
age:'12',
sex:'boy'
},{
name:'小名家',
age:'12',
sex:'boy',
children:[{
name:'小李爸',
age:'65',
sex:'boy'
},{
name:'小李妈',
age:'69',
sex:'girl'
}]
}]
console.log(JSON.parse(JSON.stringify(arr).replace(/name/g,"text")));
//输出结果:
(2) [{…}, {…}]
0: {text: '小李家', age: '12', sex: 'boy'}
1:
age: "12"
children: Array(2)
0: {text: '小李爸', age: '65', sex: 'boy'}
1: {text: '小李妈', age: '69', sex: 'girl'}
length: 2
[[Prototype]]: Array(0)
sex: "boy"
text: "小名家"
[[Prototype]]: Object
length: 2
vuejs用exceljs轻松解决excel导出表格出现的合并、居中等样式属性
上面是“js数组批量修改参数名(属性名)”的全面内容,想了解更多关于 js 内容,请继续关注web建站教程。
当前网址:https://m.ipkd.cn/webs_1919.html
声明:本站提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请发送到邮箱:admin@ipkd.cn,我们会在看到邮件的第一时间内为您处理!

nodejs如何利用Server-Sent Events实现实时发送数据
Suno APP最新版
3D粒子波浪动画效果three.js