json去除某属性
剔除age属性
方法一
1 2 3 4 5 6 7 8 9
| const arr = { name: '小王', id: 1, age: 18 }
delete arr.age console.log(arr)
|
方法二
1 2 3 4 5 6 7 8 9
| const arr = { name: '小王', id: 1, age: 18 }
const {age, ...arr2} = arr console.log(arr2)
|
方法三
1 2 3 4 5 6 7 8 9
| const arr = { name: '小王', id: 1, age: 18 }
const arr2 = { ...arr2,age:""} console.log(arr2)
|
参考资料:
https://www.cnblogs.com/chenyablog/p/11713146.html
将字符串转成数组
需求
将以下的数组中的字符串转换成正常的整数数组
1 2 3 4 5
| [ "[737, 4534, 35434]", "[1728, 392, 2713]", "[0, 0, 3]" ]
|
实操
思路:JavaScript有一个split函数可以将一段字符串指定某字符切割为字符串数组,然后再将字符串数组转换成整数数组即可。
1 2 3 4 5 6 7 8 9
| let nr=obj.data[0].replace("[","").replace("]","").split(","); let wc=obj.data[1].replace("[","").replace("]","").split(","); let st=obj.data[2].replace("[","").replace("]","").split(",");
NumberRead = nr.map(Number) WordCount = wc.map(Number) State = st.map(Number)
|