2 回答
TA贡献1796条经验 获得超10个赞
您可以使用.map():
rows_Data = rows_Data.map((entry) => ({ ...entry, file_Name: entry.file_Name.split(',') }));
例子:
let rows_Data = [{
"id": 4,
"user_id": 2,
"description": " Hi How are you ",
"post_type": 0,
"created_date": "2019-01-28T19:30:49.000Z",
"name": "sankar ",
"mobile": 9985849966,
"picture_url": "2.jpg",
"post_id": 4,
"saved_name": "9.jpg",
"file_Name": "10.jpg,9.jpg"
}, {
"id": 3,
"user_id": 1,
"description": " Working a Fine ",
"post_type": 0,
"created_date": "2019-01-25T18:40:41.000Z",
"name": "Sivasankar",
"mobile": 9985849955,
"picture_url": "5.jpg",
"post_id": 3,
"saved_name": "8.jpg",
"file_Name": "7.jpg,8.jpg"
}, {
"id": 2,
"user_id": 1,
"description": " Hello hi",
"post_type": 1,
"created_date": "2019-01-21T12:51:16.000Z",
"name": "Sivasankar",
"mobile": 9985849955,
"picture_url": "5.jpg",
"post_id": 2,
"saved_name": "4.jpg",
"file_Name": "6.jpg,5.jpg,4.jpg"
}, {
"id": 1,
"user_id": 1,
"description": " Hi How are you ",
"post_type": 0,
"created_date": "2019-01-21T12:50:51.000Z",
"name": "Sivasankar",
"mobile": 9985849955,
"picture_url": "5.jpg",
"post_id": 1,
"saved_name": "1.jpg",
"file_Name": "3.jpg,2.jpg,1.jpg"
}]
rows_Data = rows_Data.map((entry) => ({ ...entry, file_Name: entry.file_Name.split(',') }));
console.log(rows_Data);
TA贡献1757条经验 获得超8个赞
为什么不只是修改原始数组,它可以很容易地完成
rows_Data.forEach(r =>r.file_Name = r.file_Name.split(","));
或者如果您想保留原始值,只需添加一个新属性
rows_Data.forEach(r =>r.file_NameArray = r.file_Name.split(","));
rows_Data = [{
"id": 4,
"user_id": 2,
"description": " Hi How are you ",
"post_type": 0,
"created_date": "2019-01-28T19:30:49.000Z",
"name": "sankar ",
"mobile": 9985849966,
"picture_url": "2.jpg",
"post_id": 4,
"saved_name": "9.jpg",
"file_Name": "10.jpg,9.jpg"
}, {
"id": 3,
"user_id": 1,
"description": " Working a Fine ",
"post_type": 0,
"created_date": "2019-01-25T18:40:41.000Z",
"name": "Sivasankar",
"mobile": 9985849955,
"picture_url": "5.jpg",
"post_id": 3,
"saved_name": "8.jpg",
"file_Name": "7.jpg,8.jpg"
}, {
"id": 2,
"user_id": 1,
"description": " Hello hi",
"post_type": 1,
"created_date": "2019-01-21T12:51:16.000Z",
"name": "Sivasankar",
"mobile": 9985849955,
"picture_url": "5.jpg",
"post_id": 2,
"saved_name": "4.jpg",
"file_Name": "6.jpg,5.jpg,4.jpg"
}, {
"id": 1,
"user_id": 1,
"description": " Hi How are you ",
"post_type": 0,
"created_date": "2019-01-21T12:50:51.000Z",
"name": "Sivasankar",
"mobile": 9985849955,
"picture_url": "5.jpg",
"post_id": 1,
"saved_name": "1.jpg",
"file_Name": "3.jpg,2.jpg,1.jpg"
}]
console.log(rows_Data);
rows_Data.forEach(r =>r.file_Name = r.file_Name.split(","));
console.log(rows_Data)
添加回答
举报