gpt4 book ai didi

javascript - 如何将一项插入包含 15 个对象的数组中

转载 作者:行者123 更新时间:2023-12-01 02:01:05 25 4
gpt4 key购买 nike

var array1 = [{
"candidateId": 57,
"firstName": "Sumit",
"lastName": "Kumar Gupta",
"displayName": "Sumit1",
"locked": false,
"photoId": -1,
"resumeId": -1,
"experience": " 6 Months",
"email": "sumit1@test.com",
"mobile": "+91.8100688592",
"preferredLocation": [
"Bangalore"
],
"currentEmployer": [

],
"skills": [{
"skillName": "JAVA",
"level": "advanced",
"candidateRating": "5",
"rating": 0
}],
"viewed": true,
"nextStates": [{
"state": "Approach"
}]]


var array2 = [image1]

我从其他请求获取array2图像,因此我分配给array2。现在我想将此 array2 推送或添加到 array1 中。所以我创建了一个对象

'image'  
array2.push({'image':image1})

并尝试插入

for(var i=0; i<array1.length;i++){
array1[i].push(array2[i]);
}

但是没有成功。

最佳答案

array1[i]['image'] = image1;array1[i].image = image1;

您需要使用属性访问器将图像对象添加到 array1 值。

演示

var array1 = [{
"candidateId": 57,
"firstName": "Sumit",
"lastName": "Kumar Gupta",
"displayName": "Sumit1",
"locked": false,
"photoId": -1,
"resumeId": -1,
"experience": " 6 Months",
"email": "sumit1@test.com",
"mobile": "+91.8100688592",
"preferredLocation": [
"Bangalore"
],
"currentEmployer": [

],
"skills": [{
"skillName": "JAVA",
"level": "advanced",
"candidateRating": "5",
"rating": 0
}],
"viewed": true,
"nextStates": [{
"state": "Approach"
}]
}]

for (var i = 0; i < array1.length; i++) {
array1[i]['image'] = 'image1';
}
console.log(array1)

关于javascript - 如何将一项插入包含 15 个对象的数组中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50585467/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com