简体   繁体   中英

How to add a property to one element of an array?

I want to add a property to a singular element of an array.

Basically, I want to choose a singular element at random, make it appear on screen, then after it disappears add a "already chosen" property to that element so that it can't be randomly picked again.

Alternatively, if anyone knows how to temporarily exclude a single element from an array, that would be extremely helpful too.

const numbers =["1","2","3","4","5"]

you can use array of object this way

let values = [
  {
    "value": "1",
    "picked": "false",
  },
  {
    "value": "2",
    "picked": "false",
  }
  ,
  {
    "value": "3",
    "picked": "false",
  }
  ,
  {
    "value": "4",
    "picked": "false",
  }
  ,
  {
    "value": "5",
    "picked": "false",
  }
]

and every time that you pick a number give the true value to picked property

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