简体   繁体   中英

How to add a property of existing name to a javascript object

I have a javascript object with the following properties

var a
id : "Something"
value : "Something"

I want to add another property with name id is it possible in javascript?

You can just have an array of ids:

var a = {
  id: ['id1','id2'],
  value: 'something'
}

No, this not possibly. In object keys is unique.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM