-3

Having an array where length of the array is getting changes(may be increase/may be decrease) but minimum length is 1. Key values are constant for each index of array like below

Myarr =  [ 
  {stdid:1, stddesc:"",coursedetails:"xyz"},
  {stdid:2, stddesc:"ccc",coursedetails:"abc"},.......
]

I want to fetch stdid for all the available index.

Can anyone help me here.

GhostA
  • 35
  • 4

1 Answers1

0

You can use ES6 map operator.

Myarr = [{
  stdid: 1,
  stddesc: "",
  coursedetails: "xyz"
}, {
  stdid: 2,
  stddesc: "ccc",
  coursedetails: "abc"
}]
let idArr = Myarr.map(x => x.stdid);
console.log(idArr);
mplungjan
  • 169,008
  • 28
  • 173
  • 236
Karthik RP
  • 1,028
  • 16
  • 26