[英]how to find value in nested array and then change the value from boolean to string?
如何更改“活动”中的值(真为“是”/假为“否”)。
[ { "id":81, "time":"2022-01-01 19:30:00", "subList":[ { "active":false, "success":null } ] }, { "id" :89, "时间":"2022-01-01 21:00:15", "子列表":[ { "活动":true, "成功":1 } ] } ]
使用Array.map或任何其他循环来遍历数组的元素。
你可以用?
and :
条件三元运算符来缩短一个简单的 if else 块。
const list = [ { "id":81, "time":"2022-01-01 19:30:00", "subList":[ { "active":false, "success":null } ] }, { "id":89, "time":"2022-01-01 21:00:15", "subList":[ { "active":true, "success":1 } ] } ]; const newList = list.map(item => { item.subList.map(subItem => { subItem.active = subItem.active ? "Yes" : "No" return subItem; }) return item; }) console.log(newList)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.