200 何俊 201 15952428233 202 唱跳篮球 203 16~20岁 204 name111typeimageurlxxxxxx当其中包含type为image时把其中的url作为该数组的值并转换为对象结果为200 何俊 201 15952428233 202 唱跳篮球 203 16~20岁 204 xxxxxx
{ 200: "何俊", 201: "15952428233", 202: ["唱", "跳", "篮球"], 203: "16~20岁", 204: { name: "111", type: "image", url: "xxx.xxx" } }
const data = { 200: "何俊", 201: "15952428233", 202: ["唱", "跳", "篮球"], 203: "16~20岁", 204: { name: "111", type: "image", url: "xxx.xxx" } };
if (data[204].type === "image") { data[204] = data[204].url; }
console.log(data); // {200: "何俊", 201: "15952428233", 202: ["唱", "跳", "篮球"], 203: "16~20岁", 204: "xxx.xxx"}
原文地址: https://www.cveoy.top/t/topic/hb1X 著作权归作者所有。请勿转载和采集!