将新键添加到数组对象javascript

时间:2018-04-13 01:52:26

标签: javascript arrays object

const images =[
  { uri: 'images1' }, 
  { uri: 'images2' }, 
  { uri: 'images3' }, 
  { uri: 'image4' }, 

]

我希望将键添加到每个对象

const newimages =[
  { source: { uri: 'images1' } },
  { source: { uri: 'images2' } },
  { source: { uri: 'images3' } },
  { source: { uri: 'images4' } }
]

请帮助我,因为我是这个编程领域的新手。

3 个答案:

答案 0 :(得分:5)

使用SELECT RENTER.RENTER_ID, RENTER_LNAME, Round((Count(DEP_ID)+1)/APART_BED) AS "PEOPLE / BEDROOM" FROM RENTER JOIN DEPENDENT ON RENTER.RENTER_ID = DEPENDENT.RENTER_ID JOIN LEASE ON LEASE.RENTER_ID = RENTER.RENTER_ID JOIN APARTMENT ON APARTMENT.APART_NUM = LEASE.APART_NUM WHERE RENTER_ID = ((LEASE_END) = '30-JUN-18') ORDER BY RENTER_ID; 根据元素将一个数组转换为另一个数组:



.map




答案 1 :(得分:2)

您想使用地图:

BufferedReader br = new BufferedReader(new FileReader("java_module_name/src/file_name.txt"));

答案 2 :(得分:0)

欢迎使用JavaScript!
也许你可以尝试使用这样的for循环:

var images =[
  { uri: 'images1' }, 
  { uri: 'images2' }, 
  { uri: 'images3' }, 
  { uri: 'image4' }, 

];

var newImages = [];

for (i = 0; i < images.length; i++){
  newImages.push({
    source: images[i]
  })
}

console.log(newImages)